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

difftreelog

Merge remote-tracking branch 'origin/develop' into feature/NFTPAR-235-258

kpozdnikin2021-01-15parents: #3ed9616 #42edda1.patch.diff
in: master
# Conflicts:
#	tests/src/createCollection.test.ts
#	tests/src/util/helpers.ts

13 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -1153,7 +1153,7 @@
             }
 
             // Reduce approval by transferred amount or remove if remaining approval drops to 0
-            if approval - value > 0 {
+            if approval.checked_sub(value).unwrap_or(0) > 0 {
                 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);
             }
             else {
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -1,7 +1,7 @@
 // Tests to be written here
 use super::*;
 use crate::mock::*;
-use crate::{AccessMode, ApprovePermissions, CollectionMode,
+use crate::{AccessMode, CollectionMode,
     Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,
     CollectionId, TokenId, MAX_DECIMAL_POINTS};
 use frame_support::{assert_noop, assert_ok};
@@ -28,7 +28,7 @@
 }
 
 fn default_fungible_data () -> CreateFungibleData {
-    CreateFungibleData { }
+    CreateFungibleData { value: 5 }
 }
 
 fn default_re_fungible_data () -> CreateReFungibleData {
@@ -238,35 +238,35 @@
         let data = default_fungible_data();
         create_test_item(collection_id, &data.into());
 
-        assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).owner, 1);
+        assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);
     });
 }
 
-#[test]
-fn create_multiple_fungible_items() {
-    new_test_ext().execute_with(|| {
-        default_limits();
+//#[test]
+// fn create_multiple_fungible_items() {
+//     new_test_ext().execute_with(|| {
+//         default_limits();
 
-        create_test_collection(&CollectionMode::Fungible(3), 1);
+//         create_test_collection(&CollectionMode::Fungible(3), 1);
 
-        let origin1 = Origin::signed(1);
+//         let origin1 = Origin::signed(1);
 
-        let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];
+//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];
 
-        assert_ok!(TemplateModule::create_multiple_items(
-            origin1.clone(),
-            1,
-            1,
-            items_data.clone().into_iter().map(|d| { d.into() }).collect()
-        ));
+//         assert_ok!(TemplateModule::create_multiple_items(
+//             origin1.clone(),
+//             1,
+//             1,
+//             items_data.clone().into_iter().map(|d| { d.into() }).collect()
+//         ));
         
-        for (index, _) in items_data.iter().enumerate() {
-            assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).owner, 1);
-        }
-        assert_eq!(TemplateModule::balance_count(1, 1), 3000);
-        assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);
-    });
-}
+//         for (index, _) in items_data.iter().enumerate() {
+//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);
+//         }
+//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);
+//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);
+//     });
+// }
 
 #[test]
 fn transfer_fungible_item() {
@@ -281,36 +281,26 @@
         let data = default_fungible_data();
         create_test_item(collection_id, &data.into());
 
-        assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 1);
-        assert_eq!(TemplateModule::balance_count(1, 1), 1000);
-        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);
+        assert_eq!(TemplateModule::balance_count(1, 1), 5);
 
         // change owner scenario
-        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));
-        assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 2);
-        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 1000);
+        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 5));
+        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);
         assert_eq!(TemplateModule::balance_count(1, 1), 0);
-        assert_eq!(TemplateModule::balance_count(1, 2), 1000);
-        // assert_eq!(TemplateModule::address_tokens(1, 1), []);
-        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+        assert_eq!(TemplateModule::balance_count(1, 2), 5);
 
         // split item scenario
-        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 500));
-        assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 2);
-        assert_eq!(TemplateModule::fungible_item_id(1, 2).owner, 3);
-        assert_eq!(TemplateModule::balance_count(1, 2), 500);
-        assert_eq!(TemplateModule::balance_count(1, 3), 500);
-        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
-        assert_eq!(TemplateModule::address_tokens(1, 3), [2]);
+        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 3));
+        assert_eq!(TemplateModule::balance_count(1, 2), 2);
+        assert_eq!(TemplateModule::balance_count(1, 3), 3);
 
         // split item and new owner has account scenario
-        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 200));
-        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 300);
-        assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 700);
-        assert_eq!(TemplateModule::balance_count(1, 2), 300);
-        assert_eq!(TemplateModule::balance_count(1, 3), 700);
-        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
-        assert_eq!(TemplateModule::address_tokens(1, 3), [2]);
+        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 1));
+        assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);
+        assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);
+        assert_eq!(TemplateModule::balance_count(1, 2), 1);
+        assert_eq!(TemplateModule::balance_count(1, 3), 4);
     });
 }
 
@@ -451,14 +441,11 @@
             1), Error::<Test>::NoPermission);
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
         assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 2,
-                amount: 100000000
-            }
+            TemplateModule::approved(1, (1, 1, 2)),
+            5
         );
 
         assert_ok!(TemplateModule::transfer_from(
@@ -469,7 +456,7 @@
             1,
             1
         ));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
     });
 }
 
@@ -505,17 +492,10 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
-        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);
-        assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 2,
-                amount: 100000000
-            }
-        );
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
 
         assert_ok!(TemplateModule::transfer_from(
             origin2.clone(),
@@ -525,7 +505,7 @@
             1,
             1
         ));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
+        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);
     });
 }
 
@@ -560,17 +540,10 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
-        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);
-        assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 2,
-                amount: 100000000
-            }
-        );
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);
 
         assert_ok!(TemplateModule::transfer_from(
             origin2.clone(),
@@ -585,13 +558,9 @@
         assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
         assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
 
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
         assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 3,
-                amount: 100000000
-            }
+            TemplateModule::approved(1, (1, 1, 3)),
+            900
         );
     });
 }
@@ -609,8 +578,7 @@
         let origin1 = Origin::signed(1);
         let origin2 = Origin::signed(2);
 
-        assert_eq!(TemplateModule::balance_count(1, 1), 1000);
-        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+        assert_eq!(TemplateModule::balance_count(1, 1), 5);
 
         assert_ok!(TemplateModule::set_mint_permission(
             origin1.clone(),
@@ -627,16 +595,13 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
-        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
         assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 2,
-                amount: 100000000
-            }
+            TemplateModule::approved(1, (1, 1, 2)),
+            5
         );
 
         assert_ok!(TemplateModule::transfer_from(
@@ -645,37 +610,23 @@
             3,
             1,
             1,
-            100
+            4
         ));
-        assert_eq!(TemplateModule::balance_count(1, 1), 900);
-        assert_eq!(TemplateModule::balance_count(1, 3), 100);
-        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
-        assert_eq!(TemplateModule::address_tokens(1, 3), [2]);
+        assert_eq!(TemplateModule::balance_count(1, 1), 1);
+        assert_eq!(TemplateModule::balance_count(1, 3), 4);
 
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
-        assert_eq!(
-            TemplateModule::approved(1, (1, 1))[0],
-            ApprovePermissions {
-                approved: 3,
-                amount: 100000000
-            }
-        );
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);
 
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_ok!(TemplateModule::transfer_from(
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));
+        assert_noop!(TemplateModule::transfer_from(
             origin2.clone(),
             1,
             3,
             1,
             1,
-            900
-        ));
-        assert_eq!(TemplateModule::balance_count(1, 1), 0);
-        assert_eq!(TemplateModule::balance_count(1, 3), 1000);
-        // assert_eq!(TemplateModule::address_tokens(1, 1), []);
-        assert_eq!(TemplateModule::address_tokens(1, 3), [2]);
-
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
+            4
+        ), Error::<Test>::TokenValueNotEnough);
     });
 }
 
@@ -725,9 +676,9 @@
         assert_eq!(TemplateModule::balance_count(1, 1), 1);
 
         // burn item
-        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
         assert_noop!(
-            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
             Error::<Test>::TokenNotFound
         );
 
@@ -749,12 +700,12 @@
         create_test_item(collection_id, &data.into());
 
         // check balance (collection with id = 1, user id = 1)
-        assert_eq!(TemplateModule::balance_count(1, 1), 1000);
+        assert_eq!(TemplateModule::balance_count(1, 1), 5);
 
         // burn item
-        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
         assert_noop!(
-            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
             Error::<Test>::TokenNotFound
         );
 
@@ -791,9 +742,9 @@
         assert_eq!(TemplateModule::balance_count(1, 1), 1000);
 
         // burn item
-        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
+        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1000));
         assert_noop!(
-            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            TemplateModule::burn_item(origin1.clone(), 1, 1, 1000),
             Error::<Test>::TokenNotFound
         );
 
@@ -875,10 +826,10 @@
 
         // check balance (collection with id = 1, user id = 1)
         assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);
-        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 1000);
+        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);
         assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1000);
         assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);
-        assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).owner, 1);
+        assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);
         assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);
     });
 }
@@ -896,8 +847,8 @@
         let origin1 = Origin::signed(1);
         
         // approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
     });
 }
 
@@ -914,8 +865,8 @@
         create_test_item(collection_id, &data.into());
 
         // approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
 
         assert_ok!(TemplateModule::set_mint_permission(
             origin1.clone(),
@@ -1199,8 +1150,8 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
 
         assert_ok!(TemplateModule::remove_from_white_list(
             origin1.clone(),
@@ -1263,8 +1214,8 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
 
         assert_ok!(TemplateModule::remove_from_white_list(
             origin1.clone(),
@@ -1298,7 +1249,7 @@
             AccessMode::WhiteList
         ));
         assert_noop!(
-            TemplateModule::burn_item(origin1.clone(), 1, 1),
+            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
             Error::<Test>::AddresNotInWhiteList
         );
     });
@@ -1321,7 +1272,7 @@
 
         // do approve
         assert_noop!(
-            TemplateModule::approve(origin1.clone(), 1, 1, 1),
+            TemplateModule::approve(origin1.clone(), 1, 1, 1, 5),
             Error::<Test>::AddresNotInWhiteList
         );
     });
@@ -1374,8 +1325,8 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));
 
         // do approve
-        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));
-        assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);
+        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 5));
+        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);
 
         assert_ok!(TemplateModule::transfer_from(
             origin1.clone(),
modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -20,6 +20,7 @@
     "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",
     "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
+    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
     "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
     "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
addedtests/src/burnItem.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/burnItem.test.ts
@@ -0,0 +1,237 @@
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import { Keyring } from "@polkadot/api";
+import { IKeyringPair } from "@polkadot/types/types";
+import { 
+  createCollectionExpectSuccess, 
+  createItemExpectSuccess,
+  getGenericResult,
+  destroyCollectionExpectSuccess
+} from './util/helpers';
+import { nullPublicKey } from "./accounts";
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+
+describe('integration test: ext. burnItem():', () => {
+  before(async () => {
+    await usingApi(async (api) => {
+      const keyring = new Keyring({ type: 'sr25519' });
+      alice = keyring.addFromUri(`//Alice`);
+      bob = keyring.addFromUri(`//Bob`);
+    });
+  });
+
+  it('Burn item in NFT collection', async () => {
+    const createMode = 'NFT';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getGenericResult(events);
+  
+      // Get the item 
+      const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
+ 
+      // What to expect
+      expect(result.success).to.be.true;
+      expect(item).to.be.not.null;
+      expect(item.Owner).to.be.equal(nullPublicKey);
+    });
+  
+  });
+  it('Burn item in Fungible collection', async () => {
+    const createMode = 'Fungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+    await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
+    const tokenId = 0; // ignored
+
+    await usingApi(async (api) => {
+      // Destroy 1 of 10
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getGenericResult(events);
+  
+      // Get alice balance 
+      const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ 
+      // What to expect
+      expect(result.success).to.be.true;
+      expect(balance).to.be.not.null;
+      expect(balance.Value).to.be.equal(9);
+    });
+
+  });
+  it('Burn item in ReFungible collection', async () => {
+    const createMode = 'ReFungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getGenericResult(events);
+  
+      // Get alice balance 
+      const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+      
+      // What to expect
+      expect(result.success).to.be.true;
+      expect(balance).to.be.not.null;
+      expect(balance.Owner.length).to.be.equal(0);
+    });
+
+  });
+
+  it('Burn owned portion of item in ReFungible collection', async () => {
+    const createMode = 'ReFungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+    await usingApi(async (api) => {
+      // Transfer 1/100 of the token to Bob
+      const transfertx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 1);
+      const events1 = await submitTransactionAsync(alice, transfertx);
+      const result1 = getGenericResult(events1);
+
+      // Get balances
+      const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+
+      // Bob burns his portion
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const events2 = await submitTransactionAsync(bob, tx);
+      const result2 = getGenericResult(events2);
+  
+      // Get balances 
+      const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+      // console.log(balance);
+      
+      // What to expect before burning
+      expect(result1.success).to.be.true;
+      expect(balanceBefore).to.be.not.null;
+      expect(balanceBefore.Owner.length).to.be.equal(2);
+      expect(balanceBefore.Owner[0].Owner).to.be.equal(alice.address);
+      expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);
+      expect(balanceBefore.Owner[1].Owner).to.be.equal(bob.address);
+      expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);
+
+      // What to expect after burning
+      expect(result2.success).to.be.true;
+      expect(balance).to.be.not.null;
+      expect(balance.Owner.length).to.be.equal(1);
+      expect(balance.Owner[0].Fraction).to.be.equal(99);
+      expect(balance.Owner[0].Owner).to.be.equal(alice.address);
+    });
+
+  });
+
+});
+
+describe('Negative integration test: ext. burnItem():', () => {
+  before(async () => {
+    await usingApi(async (api) => {
+      const keyring = new Keyring({ type: 'sr25519' });
+      alice = keyring.addFromUri(`//Alice`);
+      bob = keyring.addFromUri(`//Bob`);
+    });
+  });
+
+  it('Burn a token in a destroyed collection', async () => {
+    const createMode = 'NFT';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+    await destroyCollectionExpectSuccess(collectionId);
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const badTransaction = async function () { 
+        await submitTransactionExpectFailAsync(alice, tx);
+      };
+      await expect(badTransaction()).to.be.rejected;
+    });
+
+  });
+
+  it('Burn a token that was never created', async () => {
+    const createMode = 'NFT';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+    const tokenId = 10;
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const badTransaction = async function () { 
+        await submitTransactionExpectFailAsync(alice, tx);
+      };
+      await expect(badTransaction()).to.be.rejected;
+    });
+
+  });
+
+  it('Burn a token using the address that does not own it', async () => {
+    const createMode = 'NFT';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+    await usingApi(async (api) => {
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const badTransaction = async function () { 
+        await submitTransactionExpectFailAsync(bob, tx);
+      };
+      await expect(badTransaction()).to.be.rejected;
+    });
+
+  });
+
+  it('Transfer a burned a token', async () => {
+    const createMode = 'NFT';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+    const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+    await usingApi(async (api) => {
+
+      const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+      const events1 = await submitTransactionAsync(alice, burntx);
+      const result1 = getGenericResult(events1);
+      expect(result1.success).to.be.true;
+  
+      const tx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 0);
+      const badTransaction = async function () { 
+        await submitTransactionExpectFailAsync(alice, tx);
+      };
+      await expect(badTransaction()).to.be.rejected;
+    });
+
+  });
+
+  it('Burn more than owned in Fungible collection', async () => {
+    const createMode = 'Fungible';
+    const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+    // Helper creates 10 fungible tokens
+    await createItemExpectSuccess(alice, collectionId, createMode);
+    const tokenId = 0; // ignored
+
+    await usingApi(async (api) => {
+      // Destroy 11 of 10
+      const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);
+      const badTransaction = async function () { 
+        await submitTransactionExpectFailAsync(alice, tx);
+      };
+      await expect(badTransaction()).to.be.rejected;
+      
+      // Get alice balance 
+      const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+ 
+      // What to expect
+      expect(balance).to.be.not.null;
+      expect(balance.Value).to.be.equal(10);
+    });
+
+  });
+
+});
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -89,7 +89,7 @@
   });
 
   it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
-    const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
 
@@ -115,7 +115,7 @@
   });
 
   it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
-    const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
 
@@ -210,7 +210,7 @@
   });
 
   it('Fungible: Sponsoring is rate limited', async () => {
-    const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
 
@@ -247,7 +247,7 @@
   });
 
   it('ReFungible: Sponsoring is rate limited', async () => {
-    const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
 
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -37,7 +37,9 @@
     await usingApi(async (api) => {
       const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
 
-      const badTransaction = async () => await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
+      const badTransaction = async () => {
+        await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
+      };
       // tslint:disable-next-line:no-unused-expression
       expect(badTransaction()).to.be.rejected;
 
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -18,17 +18,17 @@
 
   it('Create new item in NFT collection', async () => {
     const createMode = 'NFT';
-    const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
     await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
   it('Create new item in Fungible collection', async () => {
     const createMode = 'Fungible';
-    const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
     await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
   it('Create new item in ReFungible collection', async () => {
     const createMode = 'ReFungible';
-    const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
     await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
 });
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -14,11 +14,11 @@
     await destroyCollectionExpectSuccess(collectionId);
   });
   it('Fungible collection can be destroyed', async () => {
-    const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
     await destroyCollectionExpectSuccess(collectionId);
   });
   it('ReFungible collection can be destroyed', async () => {
-    const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
+    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
     await destroyCollectionExpectSuccess(collectionId);
   });
 });
addedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -0,0 +1,82 @@
+import { ApiPromise } from '@polkadot/api';
+import BN from 'bn.js';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+  it('Remove collection admin.', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionId = await createCollectionExpectSuccess();
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const collection: any = (await api.query.nft.collection(collectionId));
+      expect(collection.Owner.toString()).to.be.eq(Alice.address);
+      // first - add collection admin Bob
+      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, addAdminTx);
+
+      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);
+
+      // then remove bob from admins of collection
+      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+      await submitTransactionAsync(Alice, removeAdminTx);
+
+      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);
+    });
+  });
+});
+
+describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+  it('Can\'t remove collection admin from not existing collection', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      // tslint:disable-next-line: no-bitwise
+      const collectionId = (1 << 32) - 1;
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+
+      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);
+      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+
+      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+      await createCollectionExpectSuccess();
+    });
+  });
+
+  it('Can\'t remove collection admin from deleted collection', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      // tslint:disable-next-line: no-bitwise
+      const collectionId = await createCollectionExpectSuccess();
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+
+      await destroyCollectionExpectSuccess(collectionId);
+
+      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
+
+      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+      await createCollectionExpectSuccess();
+    });
+  });
+
+  it('Remove admin from collection that has no admins', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const collectionId = await createCollectionExpectSuccess();
+
+      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
+
+      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
+      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+    });
+  });
+});
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -32,7 +32,7 @@
   });
   it('choose or create collection for testing', async () => {
     await usingApi(async () => {
-      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
     });
   });
 });
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -30,11 +30,11 @@
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
   });
   it('Set Fungible collection sponsor', async () => {
-    const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
+    const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
   });
   it('Set ReFungible collection sponsor', async () => {
-    const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
+    const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible', decimalPoints: 0} });
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
   });
 
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -35,7 +35,7 @@
   });
   it('choose or create collection for testing', async () => {
     await usingApi(async () => {
-      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
     });
   });
 });
@@ -93,12 +93,6 @@
       const nonExistedCollectionId = collectionCount + 1;
       tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
       await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
-      /*try {
-        await submitTransactionAsync(alice, tx);
-      } catch (e) {
-        // tslint:disable-next-line:no-unused-expression
-        expect(e).to.be.exist;
-      }*/
     });
   });
 
@@ -119,13 +113,6 @@
       await destroyCollectionExpectSuccess(collectionIdForTesting);
       tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
       await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
-      /*try {
-        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
-        await submitTransactionAsync(alice, tx);
-      } catch (e) {
-        // tslint:disable-next-line:no-unused-expression
-        expect(e).to.be.exist;
-      }*/
     });
   });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
before · tests/src/util/helpers.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise, Keyring } from '@polkadot/api';7import { Enum, Struct } from '@polkadot/types/codec';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';9import { u128 } from '@polkadot/types/primitive';10import { IKeyringPair } from '@polkadot/types/types';11import { BigNumber } from 'bignumber.js';12import BN from 'bn.js';13import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15import { alicesPublicKey, nullPublicKey } from '../accounts';16import privateKey from '../substrate/privateKey';17import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';18import { ICollectionInterface } from '../types';19import { hexToStr, strToUTF16, utf16ToStr } from './util';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324type GenericResult = {25  success: boolean,26};2728interface CreateCollectionResult {29  success: boolean;30  collectionId: number;31}3233interface CreateItemResult {34  success: boolean;35  collectionId: number;36  itemId: number;37}3839interface ITokenDataType {40  Owner: number[];41  ConstData: number[];42  VariableData: number[];43}4445export function getGenericResult(events: EventRecord[]): GenericResult {46  const result: GenericResult = {47    success: false,48  };49  events.forEach(({ phase, event: { data, method, section } }) => {50    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);51    if (method === 'ExtrinsicSuccess') {52      result.success = true;53    }54  });55  return result;56}5758export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {59  let success = false;60  let collectionId: number = 0;61  events.forEach(({ phase, event: { data, method, section } }) => {62    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);63    if (method == 'ExtrinsicSuccess') {64      success = true;65    } else if ((section == 'nft') && (method == 'Created')) {66      collectionId = parseInt(data[0].toString());67    }68  });69  const result: CreateCollectionResult = {70    success,71    collectionId,72  };73  return result;74}7576export function getCreateItemResult(events: EventRecord[]): CreateItemResult {77  let success = false;78  let collectionId: number = 0;79  let itemId: number = 0;80  events.forEach(({ phase, event: { data, method, section } }) => {81    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);82    if (method == 'ExtrinsicSuccess') {83      success = true;84    } else if ((section == 'nft') && (method == 'ItemCreated')) {85      collectionId = parseInt(data[0].toString());86      itemId = parseInt(data[1].toString());87    }88  });89  const result: CreateItemResult = {90    success,91    collectionId,92    itemId,93  };94  return result;95}9697interface Invalid {98  type: 'Invalid';99}100101interface Nft {102  type: 'NFT';103}104105interface Fungible {106  type: 'Fungible';107  decimalPoints: number;108}109110interface ReFungible {111  type: 'ReFungible';112  decimalPoints: number;113}114115type CollectionMode = Nft | Fungible | ReFungible | Invalid;116117export type CreateCollectionParams = {118  mode: CollectionMode,119  name: string,120  description: string,121  tokenPrefix: string,122};123124const defaultCreateCollectionParams: CreateCollectionParams = {125  description: 'description',126  mode: { type: 'NFT' },127  name: 'name',128  tokenPrefix: 'prefix',129}130131export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {132  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};133134  let collectionId: number = 0;135  await usingApi(async (api) => {136    // Get number of collections before the transaction137    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);138139    // Run the CreateCollection transaction140    const alicePrivateKey = privateKey('//Alice');141142    let modeprm = {};143    if (mode.type === 'NFT') {144      modeprm = {nft: null};145    } else if (mode.type === 'Fungible') {146      modeprm = {fungible: mode.decimalPoints};147    } else if (mode.type === 'ReFungible') {148      modeprm = {refungible: mode.decimalPoints};149    } else if (mode.type === 'Invalid') {150      modeprm = {invalid: null};151    }152153    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);154    const events = await submitTransactionAsync(alicePrivateKey, tx);155    const result = getCreateCollectionResult(events);156157    // Get number of collections after the transaction158    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);159160    // Get the collection161    const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();162163    // What to expect164    // tslint:disable-next-line:no-unused-expression165    expect(result.success).to.be.true;166    expect(result.collectionId).to.be.equal(BcollectionCount);167    // tslint:disable-next-line:no-unused-expression168    expect(collection).to.be.not.null;169    expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');170    expect(collection.Owner).to.be.equal(alicesPublicKey);171    expect(utf16ToStr(collection.Name)).to.be.equal(name);172    expect(utf16ToStr(collection.Description)).to.be.equal(description);173    expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);174175    collectionId = result.collectionId;176  });177178  return collectionId;179}180181export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {182  const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};183184  let modeprm = {};185  if (mode.type === 'NFT') {186    modeprm = {nft: null};187  } else if (mode.type === 'Fungible') {188    modeprm = {fungible: mode.decimalPoints};189  } else if (mode.type === 'ReFungible') {190    modeprm = {refungible: mode.decimalPoints};191  } else if (mode.type === 'Invalid') {192    modeprm = {invalid: null};193  }194195  await usingApi(async (api) => {196    // Get number of collections before the transaction197    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());198199    // Run the CreateCollection transaction200    const alicePrivateKey = privateKey('//Alice');201    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);202    const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;203    const result = getCreateCollectionResult(events);204205    // Get number of collections after the transaction206    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());207208    // What to expect209    // tslint:disable-next-line:no-unused-expression210    expect(result.success).to.be.false;211    expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');212  });213}214215export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {216  let bal = new BigNumber(0);217  let unused;218  do {219    const randomSeed = 'seed' +  Math.floor(Math.random() * Math.floor(10000));220    const keyring = new Keyring({ type: 'sr25519' });221    unused = keyring.addFromUri(`//${randomSeed}`);222    bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());223  } while (bal.toFixed() != '0');224  return unused;225}226227function getDestroyResult(events: EventRecord[]): boolean {228  let success: boolean = false;229  events.forEach(({ phase, event: { data, method, section } }) => {230    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);231    if (method == 'ExtrinsicSuccess') {232      success = true;233    }234  });235  return success;236}237238export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {239  await usingApi(async (api) => {240    // Run the DestroyCollection transaction241    const alicePrivateKey = privateKey(senderSeed);242    const tx = api.tx.nft.destroyCollection(collectionId);243    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;244  });245}246247export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {248  await usingApi(async (api) => {249    // Run the DestroyCollection transaction250    const alicePrivateKey = privateKey(senderSeed);251    const tx = api.tx.nft.destroyCollection(collectionId);252    const events = await submitTransactionAsync(alicePrivateKey, tx);253    const result = getDestroyResult(events);254255    // Get the collection256    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();257258    // What to expect259    expect(result).to.be.true;260    expect(collection).to.be.not.null;261    expect(collection.Owner).to.be.equal(nullPublicKey);262  });263}264265export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {266  await usingApi(async (api) => {267268    // Run the transaction269    const alicePrivateKey = privateKey('//Alice');270    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);271    const events = await submitTransactionAsync(alicePrivateKey, tx);272    const result = getGenericResult(events);273274    // Get the collection275    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();276277    // What to expect278    expect(result.success).to.be.true;279    expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());280    expect(collection.SponsorConfirmed).to.be.false;281  });282}283284export async function removeCollectionSponsorExpectSuccess(collectionId: number) {285  await usingApi(async (api) => {286287    // Run the transaction288    const alicePrivateKey = privateKey('//Alice');289    const tx = api.tx.nft.removeCollectionSponsor(collectionId);290    const events = await submitTransactionAsync(alicePrivateKey, tx);291    const result = getGenericResult(events);292293    // Get the collection294    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();295296    // What to expect297    expect(result.success).to.be.true;298    expect(collection.Sponsor).to.be.equal(nullPublicKey);299    expect(collection.SponsorConfirmed).to.be.false;300  });301}302303export async function removeCollectionSponsorExpectFailure(collectionId: number) {304  await usingApi(async (api) => {305306    // Run the transaction307    const alicePrivateKey = privateKey('//Alice');308    const tx = api.tx.nft.removeCollectionSponsor(collectionId);309    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;310  });311}312313export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {314  await usingApi(async (api) => {315316    // Run the transaction317    const alicePrivateKey = privateKey(senderSeed);318    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);319    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;320  });321}322323export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {324  await usingApi(async (api) => {325326    // Run the transaction327    const sender = privateKey(senderSeed);328    const tx = api.tx.nft.confirmSponsorship(collectionId);329    const events = await submitTransactionAsync(sender, tx);330    const result = getGenericResult(events);331332    // Get the collection333    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();334335    // What to expect336    expect(result.success).to.be.true;337    expect(collection.Sponsor).to.be.equal(sender.address);338    expect(collection.SponsorConfirmed).to.be.true;339  });340}341342export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {343  await usingApi(async (api) => {344345    // Run the transaction346    const sender = privateKey(senderSeed);347    const tx = api.tx.nft.confirmSponsorship(collectionId);348    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;349  });350}351352export interface CreateFungibleData extends Struct {353  readonly value: u128;354}355356export interface CreateReFungibleData extends Struct {}357export interface CreateNftData extends Struct {}358359export interface CreateItemData extends Enum {360  NFT: CreateNftData;361  Fungible: CreateFungibleData;362  ReFungible: CreateReFungibleData;363}364365export async function366approveExpectSuccess(collectionId: number,367                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {368  await usingApi(async (api: ApiPromise) => {369    const allowanceBefore =370      await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;371    const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);372    const events = await submitTransactionAsync(owner, approveNftTx);373    const result = getCreateItemResult(events);374    // tslint:disable-next-line:no-unused-expression375    expect(result.success).to.be.true;376    const allowanceAfter =377      await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;378    expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);379  });380}381382export async function383transferFromExpectSuccess(collectionId: number, tokenId: number, accountFrom: IKeyringPair,384                          accountTo: IKeyringPair, value: number = 1, type: string = 'NFT') {385  await usingApi(async (api: ApiPromise) => {386    const transferFromTx = await api.tx.nft.transferFrom(387      accountFrom.address, accountTo.address, collectionId, tokenId, value);388    const events = await submitTransactionAsync(accountFrom, transferFromTx);389    const result = getCreateItemResult(events);390    // tslint:disable-next-line:no-unused-expression391    expect(result.success).to.be.true;392    if (type === 'NFT') {393      const nftItemData = api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;394      console.log('NFT data', nftItemData);395    }396    if (type === 'Fungible') {397      const nftItemData = api.query.nft.fungibleItemList(collectionId, tokenId) as unknown as ITokenDataType;398      console.log('Fungible data', nftItemData);399    }400    if (type === 'ReFungible') {401      const nftItemData = api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as ITokenDataType;402      console.log('reFungibleItemList data', nftItemData);403    }404  });405}406407export async function408approveExpectFail(collectionId: number,409                  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {410  await usingApi(async (api: ApiPromise) => {411    const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);412    const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;413    const result = getCreateCollectionResult(events);414    // tslint:disable-next-line:no-unused-expression415    expect(result.success).to.be.false;416  });417}418419export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {420  let newItemId: number = 0;421  await usingApi(async (api) => {422    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);423    const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();424    const AItemBalance = new BigNumber(Aitem.Value);425426    if (owner === '') {427      owner = sender.address;428    }429430    let tx;431    if (createMode === 'Fungible') {432      const createData = {fungible: {value: 10}};433      tx = api.tx.nft.createItem(collectionId, owner, createData);434    } else {435      tx = api.tx.nft.createItem(collectionId, owner, createMode);436    }437    const events = await submitTransactionAsync(sender, tx);438    const result = getCreateItemResult(events);439440    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);441    const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();442    const BItemBalance = new BigNumber(Bitem.Value);443444    // What to expect445    // tslint:disable-next-line:no-unused-expression446    expect(result.success).to.be.true;447    if (createMode === 'Fungible') {448      expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);449    } else {450      expect(BItemCount).to.be.equal(AItemCount + 1);451    }452    expect(collectionId).to.be.equal(result.collectionId);453    expect(BItemCount).to.be.equal(result.itemId);454    newItemId = result.itemId;455  });456  return newItemId;457}458459export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {460  await usingApi(async (api) => {461462    // Run the transaction463    const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');464    const events = await submitTransactionAsync(sender, tx);465    const result = getGenericResult(events);466467    // Get the collection468    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();469470    // What to expect471    expect(result.success).to.be.true;472    expect(collection.Access).to.be.equal('WhiteList');473  });474}475476export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {477  await usingApi(async (api) => {478479    // Run the transaction480    const tx = api.tx.nft.setMintPermission(collectionId, true);481    const events = await submitTransactionAsync(sender, tx);482    const result = getGenericResult(events);483484    // Get the collection485    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();486487    // What to expect488    expect(result.success).to.be.true;489    expect(collection.MintMode).to.be.equal(true);490  });491}492493export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {494  await usingApi(async (api) => {495496    // Run the transaction497    const tx = api.tx.nft.addToWhiteList(collectionId, address);498    const events = await submitTransactionAsync(sender, tx);499    const result = getGenericResult(events);500501    // Get the collection502    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();503504    // What to expect505    expect(result.success).to.be.true;506    expect(collection.MintMode).to.be.equal(true);507  });508}509510export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)511  : Promise<ICollectionInterface | null> => {512  return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;513};514515export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {516  // set global object - collectionsCount517  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();518};