git.delta.rocks / unique-network / refs/commits / 516483006d10

difftreelog

test use rtt from metadata

Yaroslav Bolyukin2021-10-26parent: #a8ad5e0.patch.diff
in: master

33 files changed

modifieddocker-compose-tests-parachain.ymldiffbeforeafterboth
--- a/docker-compose-tests-parachain.yml
+++ b/docker-compose-tests-parachain.yml
@@ -7,7 +7,7 @@
     ports:
       - 9944:9944
       - 9844:9844
-      - 9933:9934
+      - 9933:9933
     build:
       context: ./
       dockerfile: Dockerfile-parachain
@@ -19,7 +19,6 @@
     volumes:
 #      - ./chain-data:/chain-data
       - ./launch-config.json:/polkadot-launch/launch-config.json
-      - ./runtime_types.json:/polkadot-launch/runtime_types.json
     env_file:
       - ./.env
     networks:
@@ -34,11 +33,10 @@
       context: tests/
       dockerfile: Dockerfile-tests
     environment:
-      RPC_URL: http://blockchain_nodes:9934/
+      RPC_URL: http://blockchain_nodes:9933/
     volumes:
       - ./tests/src/config_docker.ts:/nft_parachain/src/config.ts
       - /home/ubuntu/mochawesome-report:/nft_parachain/mochawesome-report
-      - ./runtime_types.json:/runtime_types.json
 #    command: bash -c 'while true; do sleep 20; df -h; done'
     networks:
       - node_test_network
modifiedexamples/re-fungible/create_collection.jsdiffbeforeafterboth
--- a/examples/re-fungible/create_collection.js
+++ b/examples/re-fungible/create_collection.js
@@ -8,7 +8,7 @@
       const unsub = await transaction
       .signAndSend(sender, (result) => {
         console.log(`Current tx status is ${result.status}`);
-    
+
         if (result.status.isInBlock) {
           console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
           resolve();
@@ -33,7 +33,7 @@
   const description = [67, 111, 108, 108, 101, 99, 116, 105, 111, 110, 32, 111, 102, 32, 112, 104, 111, 116, 111, 115];
   // ART
   const tokenPrefix = [65, 82, 84];
-  
+
   // Mode: Re-Fungible
   const tx = api.tx.nft.createCollection(name, description, tokenPrefix, {"ReFungible": [config.collectionDataSize, config.decimalPoints]});
   await submitTransaction(alice, tx);
@@ -45,18 +45,15 @@
 async function main() {
   // Initialise the provider to connect to the node
   const wsProvider = new WsProvider(config.wsEndpoint);
-  const rtt = JSON.parse(fs.readFileSync("runtime_types.json"));
-
   // Create the API and wait until ready
-  const api = await ApiPromise.create({ 
+  const api = await ApiPromise.create({
     provider: wsProvider,
-    types: rtt
   });
 
   // Owners's keypair
   const keyring = new Keyring({ type: 'sr25519' });
   const owner = keyring.addFromUri(config.ownerSeed);
-  console.log("Collection owner address: ", owner.address);  
+  console.log("Collection owner address: ", owner.address);
 
   // Create collection as owner
   console.log("=== Create collection ===");
modifiedexamples/testnft/create_collection.jsdiffbeforeafterboth
--- a/examples/testnft/create_collection.js
+++ b/examples/testnft/create_collection.js
@@ -9,7 +9,7 @@
       const unsub = await transaction
       .signAndSend(sender, (result) => {
         console.log(`Current tx status is ${result.status}`);
-    
+
         if (result.status.isInBlock) {
           console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
           resolve();
@@ -34,7 +34,7 @@
   const description = [0x54, 0x65, 0x73, 0x74, 0x20, 0x4e, 0x46, 0x54, 0x20, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e];
   // TestNFT
   const tokenPrefix = [0x54, 0x65, 0x73, 0x74, 0x4e, 0x46, 0x54];
-  
+
   // Mode: NFT
   const tx = api.tx.nft.createCollection(name, description, tokenPrefix, {"NFT": config.collectionDataSize});
   await submitTransaction(alice, tx);
@@ -48,18 +48,16 @@
 async function main() {
   // Initialise the provider to connect to the node
   const wsProvider = new WsProvider(config.wsEndpoint);
-  const rtt = JSON.parse(fs.readFileSync("runtime_types.json"));
 
   // Create the API and wait until ready
-  const api = await ApiPromise.create({ 
+  const api = await ApiPromise.create({
     provider: wsProvider,
-    types: rtt
   });
 
   // Owners's keypair
   const keyring = new Keyring({ type: 'sr25519' });
   const owner = keyring.addFromUri(config.ownerSeed);
-  console.log("Collection owner address: ", owner.address);  
+  console.log("Collection owner address: ", owner.address);
 
   // Create collection as owner
   console.log("=== Create collection ===");
modifiedexamples/testnft/create_tokens.jsdiffbeforeafterboth
--- a/examples/testnft/create_tokens.js
+++ b/examples/testnft/create_tokens.js
@@ -17,7 +17,7 @@
       .createItem(collectionId, "0x", admin.address)
       .signAndSend(admin, (result) => {
         console.log(`Current tx status is ${result.status}`);
-    
+
         if (result.status.isInBlock) {
           console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
           resolve();
@@ -34,12 +34,10 @@
 async function main() {
   // Initialise the provider to connect to the node
   const wsProvider = new WsProvider(config.wsEndpoint);
-  const rtt = require("./runtime_types.json");
 
   // Create the API and wait until ready
-  const api = await ApiPromise.create({ 
+  const api = await ApiPromise.create({
     provider: wsProvider,
-    types: rtt
   });
 
   // Retrieve the chain & node information information via rpc calls
@@ -53,7 +51,7 @@
   console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
   console.log(`Collection: ${collection}`);
 
-  if (checkOwner(collection.Owner.toString())) {
+  if (checkOwner(collection.owner.toString())) {
     // Import account from mnemonic phrase in config file
     const keyring = new Keyring({ type: 'sr25519' });
     const owner = keyring.addFromUri(config.ownerSeed);
modifiedlaunch-config.jsondiffbeforeafterboth
--- a/launch-config.json
+++ b/launch-config.json
@@ -88,6 +88,5 @@
     ],
     "simpleParachains": [],
     "hrmpChannels": [],
-    "types": "./runtime_types.json",
     "finalization": false
 }
modifiedlaunch-test-env.shdiffbeforeafterboth
--- a/launch-test-env.sh
+++ b/launch-test-env.sh
@@ -1,7 +1,6 @@
 cp launch-config.json ../polkadot-launch/launch-config.json
-cp runtime_types.json ../polkadot-launch/runtime_types.json
 
 cd ../polkadot-launch
 yarn install
 yarn build
-yarn start launch-config.json
\ No newline at end of file
+yarn start launch-config.json
deletedruntime_types.jsondiffbeforeafterboth
--- a/runtime_types.json
+++ /dev/null
@@ -1,128 +0,0 @@
-{
-    "AccountInfo": "AccountInfoWithTripleRefCount",
-    "CrossAccountId": {
-      "_enum": {
-        "substrate": "AccountId",
-        "ethereum": "H160"
-      }
-    },
-    "AccessMode": {
-      "_enum": [
-        "Normal",
-        "WhiteList"
-      ]
-    },
-    "CallSpec": {
-      "Module": "u32",
-      "Method": "u32"
-    },
-    "DecimalPoints": "u8",
-    "CollectionMode": {
-      "_enum": {
-        "NFT": null,
-        "Fungible": "DecimalPoints",
-        "ReFungible": null
-      }
-    },
-    "Ownership": {
-      "Owner": "CrossAccountId",
-      "Fraction": "u128"
-    },
-    "FungibleItemType": {
-      "Value": "u128"
-    },
-    "NftItemType": {
-      "Owner": "CrossAccountId",
-      "ConstData": "Vec<u8>",
-      "VariableData": "Vec<u8>"
-    },
-    "ReFungibleItemType": {
-      "Owner": "Vec<Ownership<CrossAccountId>>",
-      "ConstData": "Vec<u8>",
-      "VariableData": "Vec<u8>"
-    },
-    "SponsorshipState": {
-      "_enum": {
-        "disabled": null,
-        "unconfirmed": "AccountId",
-        "confirmed": "AccountId"
-      }
-    },
-    "Collection": {
-      "Owner": "AccountId",
-      "Mode": "CollectionMode",
-      "Access": "AccessMode",
-      "DecimalPoints": "DecimalPoints",
-      "Name": "Vec<u16>",
-      "Description": "Vec<u16>",
-      "TokenPrefix": "Vec<u8>",
-      "MintMode": "bool",
-      "OffchainSchema": "Vec<u8>",
-      "SchemaVersion": "SchemaVersion",
-      "Sponsorship": "SponsorshipState",
-      "Limits": "CollectionLimits",
-      "VariableOnChainSchema": "Vec<u8>",
-      "ConstOnChainSchema": "Vec<u8>",
-      "MetaUpdatePermission": "MetaUpdatePermission",
-      "TransfersEnabled": "bool"
-    },
-    "RawData": "Vec<u8>",
-    "Address": "MultiAddress",
-    "LookupSource": "MultiAddress",
-    "Weight": "u64",
-    "CreateNftData": {
-      "const_data": "Vec<u8>",
-      "variable_data": "Vec<u8>" 
-    },
-    "CreateFungibleData": {
-      "value": "u128"
-    },
-    "CreateReFungibleData": {
-      "const_data": "Vec<u8>",
-      "variable_data": "Vec<u8>",
-      "pieces": "u128"
-    },
-    "CreateItemData": {
-      "_enum": {
-        "NFT": "CreateNftData",
-        "Fungible": "CreateFungibleData",
-        "ReFungible": "CreateReFungibleData"
-      }
-    },
-    "SchemaVersion": {
-      "_enum": [
-        "ImageURL",
-        "Unique"
-      ]
-    },
-    "MetaUpdatePermission": {
-      "_enum": [
-        "ItemOwner",
-        "Admin",
-        "None"      
-      ]
-    },
-    "CollectionId": "u32",
-    "TokenId": "u32",
-    "ChainLimits": {
-      "CollectionNumbersLimit": "u32",
-      "AccountTokenOwnershipLimit": "u32",
-      "CollectionAdminsLimit": "u64",
-      "CustomDataLimit": "u32",
-      "NftSponsorTimeout": "u32",
-      "FungibleSponsorTimeout": "u32",
-      "RefungibleSponsorTimeout": "u32",
-      "OffchainSchemaLimit": "u32",
-      "VariableOnChainSchemaLimit": "u32",
-      "ConstOnChainSchemaLimit": "u32"
-    },
-    "CollectionLimits": {
-      "AccountTokenOwnershipLimit": "u32",
-      "SponsoredDataSize": "u32",
-      "SponsoredDataRateLimit": "Option<BlockNumber>",
-      "TokenLimit": "u32",
-      "SponsorTimeout": "u32",
-      "OwnerCanTransfer": "bool",
-      "OwnerCanDestroy": "bool"
-    }
-}
\ No newline at end of file
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -21,7 +21,7 @@
       const bob = privateKey('//Bob');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.equal(alice.address);
+      expect(collection.owner).to.be.equal(alice.address);
 
       const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
       await submitTransactionAsync(alice, changeAdminTx);
@@ -39,7 +39,7 @@
       const Charlie = privateKey('//CHARLIE');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.equal(Alice.address);
+      expect(collection.owner).to.be.equal(Alice.address);
 
       const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
       await submitTransactionAsync(Alice, changeAdminTx);
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -173,7 +173,7 @@
   it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
     const collectionId = await createCollectionExpectSuccess();
     const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });
 
     await approveExpectFail(collectionId, itemId, Alice, Charlie);
   });
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -6,8 +6,8 @@
 import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
 import { Keyring } from '@polkadot/api';
 import { IKeyringPair } from '@polkadot/types/types';
-import { 
-  createCollectionExpectSuccess, 
+import {
+  createCollectionExpectSuccess,
   createItemExpectSuccess,
   getGenericResult,
   destroyCollectionExpectSuccess,
@@ -62,14 +62,14 @@
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
-  
-      // Get alice balance 
+
+      // 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);
+      expect(balance.value).to.be.equal(9);
     });
   });
 
@@ -82,10 +82,10 @@
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
-  
-      // Get alice balance 
+
+      // 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.null;
@@ -111,25 +111,25 @@
       const events2 = await submitTransactionAsync(bob, tx);
       const result2 = getGenericResult(events2);
 
-      // Get balances 
+      // 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.deep.equal(normalizeAccountId(alice.address));
-      expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);
-      expect(balanceBefore.Owner[1].Owner).to.be.deep.equal(normalizeAccountId(bob.address));
-      expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);
+      expect(balanceBefore.owner.length).to.be.equal(2);
+      expect(balanceBefore.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
+      expect(balanceBefore.owner[0].fraction).to.be.equal(99);
+      expect(balanceBefore.owner[1].owner).to.be.deep.equal(normalizeAccountId(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.deep.equal(normalizeAccountId(alice.address));
+      expect(balance.owner.length).to.be.equal(1);
+      expect(balance.owner[0].fraction).to.be.equal(99);
+      expect(balance.owner[0].owner).to.be.deep.equal(normalizeAccountId(alice.address));
     });
 
   });
@@ -183,7 +183,7 @@
 
     await usingApi(async (api) => {
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
-      const badTransaction = async function () { 
+      const badTransaction = async function () {
         await submitTransactionExpectFailAsync(alice, tx);
       };
       await expect(badTransaction()).to.be.rejected;
@@ -198,7 +198,7 @@
 
     await usingApi(async (api) => {
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
-      const badTransaction = async function () { 
+      const badTransaction = async function () {
         await submitTransactionExpectFailAsync(alice, tx);
       };
       await expect(badTransaction()).to.be.rejected;
@@ -213,7 +213,7 @@
 
     await usingApi(async (api) => {
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
-      const badTransaction = async function () { 
+      const badTransaction = async function () {
         await submitTransactionExpectFailAsync(bob, tx);
       };
       await expect(badTransaction()).to.be.rejected;
@@ -232,9 +232,9 @@
       const events1 = await submitTransactionAsync(alice, burntx);
       const result1 = getGenericResult(events1);
       expect(result1.success).to.be.true;
-  
+
       const tx = api.tx.nft.transfer(normalizeAccountId(bob.address), collectionId, tokenId, 0);
-      const badTransaction = async function () { 
+      const badTransaction = async function () {
         await submitTransactionExpectFailAsync(alice, tx);
       };
       await expect(badTransaction()).to.be.rejected;
@@ -252,17 +252,17 @@
     await usingApi(async (api) => {
       // Destroy 11 of 10
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);
-      const badTransaction = async function () { 
+      const badTransaction = async function () {
         await submitTransactionExpectFailAsync(alice, tx);
       };
       await expect(badTransaction()).to.be.rejected;
-      
-      // Get alice balance 
+
+      // 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);
+      expect(balance.value).to.be.equal(10);
     });
 
   });
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -7,7 +7,7 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
 import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import { createCollectionExpectSuccess, 
+import { createCollectionExpectSuccess,
   addCollectionAdminExpectSuccess,
   setCollectionSponsorExpectSuccess,
   confirmSponsorshipExpectSuccess,
@@ -35,13 +35,13 @@
       const bob = privateKey('//Bob');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(alice.address);
+      expect(collection.owner).to.be.deep.eq(alice.address);
 
       const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
       await submitTransactionAsync(alice, changeOwnerTx);
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
     });
   });
 });
@@ -54,7 +54,7 @@
       const bob = privateKey('//Bob');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(alice.address);
+      expect(collection.owner).to.be.deep.eq(alice.address);
 
       const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
       await submitTransactionAsync(alice, changeOwnerTx);
@@ -63,7 +63,7 @@
       await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
     });
   });
 
@@ -75,13 +75,13 @@
       const charlie = privateKey('//Charlie');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(alice.address);
+      expect(collection.owner).to.be.deep.eq(alice.address);
 
       const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
       await submitTransactionAsync(alice, changeOwnerTx);
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
 
       // After changing the owner of the collection, all privileged methods are available to the new owner
       // The new owner of the collection has access to sponsorship management operations in the collection
@@ -91,12 +91,12 @@
 
       // The new owner of the collection has access to operations for managing the collection parameters
       const collectionLimits = {
-        AccountTokenOwnershipLimit: 1,
-        SponsoredMintSize: 1,
-        TokenLimit: 1,
-        SponsorTimeout: 1,
-        OwnerCanTransfer: true,
-        OwnerCanDestroy: true,
+        accountTokenOwnershipLimit: 1,
+        sponsoredMintSize: 1,
+        tokenLimit: 1,
+        sponsorTimeout: 1,
+        ownerCanTransfer: true,
+        ownerCanDestroy: true,
       };
       const tx1 = api.tx.nft.setCollectionLimits(
         collectionId,
@@ -117,22 +117,22 @@
       const alice = privateKey('//Alice');
       const bob = privateKey('//Bob');
       const charlie = privateKey('//Charlie');
-  
+
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(alice.address);
-  
+      expect(collection.owner).to.be.deep.eq(alice.address);
+
       const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
       await submitTransactionAsync(alice, changeOwnerTx);
-  
+
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
 
       const changeOwnerTx2 = api.tx.nft.changeCollectionOwner(collectionId, charlie.address);
       await submitTransactionAsync(bob, changeOwnerTx2);
-  
+
       // ownership lost
       const collectionAfterOwnerChange2: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange2.Owner).to.be.deep.eq(charlie.address);
+      expect(collectionAfterOwnerChange2.owner).to.be.deep.eq(charlie.address);
     });
   });
 });
@@ -148,7 +148,7 @@
       await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
       await createCollectionExpectSuccess();
@@ -167,7 +167,7 @@
       await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(alice.address);
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
       await createCollectionExpectSuccess();
@@ -196,7 +196,7 @@
       const charlie = privateKey('//Charlie');
 
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(alice.address);
+      expect(collection.owner).to.be.deep.eq(alice.address);
 
       const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
       await submitTransactionAsync(alice, changeOwnerTx);
@@ -205,19 +205,19 @@
       await expect(submitTransactionExpectFailAsync(alice, badChangeOwnerTx)).to.be.rejected;
 
       const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(bob.address);
+      expect(collectionAfterOwnerChange.owner).to.be.deep.eq(bob.address);
 
       await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Alice');
       await confirmSponsorshipExpectFailure(collectionId, '//Alice');
       await removeCollectionSponsorExpectFailure(collectionId, '//Alice');
 
       const collectionLimits = {
-        AccountTokenOwnershipLimit: 1,
-        SponsoredMintSize: 1,
-        TokenLimit: 1,
-        SponsorTimeout: 1,
-        OwnerCanTransfer: true,
-        OwnerCanDestroy: true,
+        accountTokenOwnershipLimit: 1,
+        sponsoredMintSize: 1,
+        tokenLimit: 1,
+        sponsorTimeout: 1,
+        ownerCanTransfer: true,
+        ownerCanDestroy: true,
       };
       const tx1 = api.tx.nft.setCollectionLimits(
         collectionId,
modifiedtests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/admVsOwnerChanges.test.ts
+++ b/tests/src/collision-tests/admVsOwnerChanges.test.ts
@@ -27,7 +27,7 @@
 describe('Admin vs Owner changes token: ', () => {
   // tslint:disable-next-line: max-line-length
   it('The collection admin changes the owner of the token and in the same block the current owner transfers the token to another address ', async () => {
-    
+
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
@@ -35,7 +35,7 @@
       const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Ferdie.address));
       await submitTransactionAsync(Bob, changeAdminTxFerdie);
       const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
-      
+
       const changeOwner = api.tx.nft.transferFrom(normalizeAccountId(Ferdie.address), normalizeAccountId(Bob.address), collectionId, itemId, 1);
       const approve = api.tx.nft.approve(normalizeAccountId(Bob.address), collectionId, itemId, 1);
       const sendItem = api.tx.nft.transfer(normalizeAccountId(Alice.address), collectionId, itemId, 1);
@@ -45,7 +45,7 @@
         sendItem.signAndSend(Ferdie),
       ]);
       const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
-      expect(itemBefore.Owner).not.to.be.eq(Bob.address);
+      expect(itemBefore.owner).not.to.be.eq(Bob.address);
       await waitNewBlocks(2);
     });
   });
modifiedtests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/admVsOwnerData.test.ts
+++ b/tests/src/collision-tests/admVsOwnerData.test.ts
@@ -41,7 +41,7 @@
         BobTx.signAndSend(Bob),
       ]);
       const item: any = await api.query.nft.nftItemList(collectionId, itemId);
-      expect(item.VariableData).not.to.be.eq(null); // Pseudo-random selection of one of two values
+      expect(item.variableData).not.to.be.eq(null); // Pseudo-random selection of one of two values
       await waitNewBlocks(2);
     });
   });
modifiedtests/src/collision-tests/setSponsorNewOwner.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/setSponsorNewOwner.test.ts
+++ b/tests/src/collision-tests/setSponsorNewOwner.test.ts
@@ -4,7 +4,7 @@
 import privateKey from '../substrate/privateKey';
 import usingApi from '../substrate/substrate-api';
 import {
-  createCollectionExpectSuccess, 
+  createCollectionExpectSuccess,
   setCollectionSponsorExpectSuccess,
   waitNewBlocks,
 } from '../util/helpers';
@@ -38,8 +38,8 @@
       ]);
       await waitNewBlocks(2);
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Sponsorship.confirmed).to.be.eq(Bob.address);
-      expect(collection.Owner).to.be.eq(Ferdie.address);
+      expect(collection.sponsorship.confirmed).to.be.eq(Bob.address);
+      expect(collection.owner).to.be.eq(Ferdie.address);
       await waitNewBlocks(2);
     });
   });
modifiedtests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth
--- a/tests/src/collision-tests/tokenLimitsOff.test.ts
+++ b/tests/src/collision-tests/tokenLimitsOff.test.ts
@@ -19,12 +19,12 @@
 let Bob: IKeyringPair;
 let Ferdie: IKeyringPair;
 
-const AccountTokenOwnershipLimit = 4;
-const SponsoredMintSize = 4294967295;
-const TokenLimit = 4;
-const SponsorTimeout = 14400;
-const OwnerCanTransfer = false;
-const OwnerCanDestroy = false;
+const accountTokenOwnershipLimit = 4;
+const sponsoredMintSize = 4294967295;
+const tokenLimit = 4;
+const sponsorTimeout = 14400;
+const ownerCanTransfer = false;
+const ownerCanDestroy = false;
 
 before(async () => {
   await usingApi(async () => {
@@ -45,13 +45,13 @@
       const setCollectionLim = api.tx.nft.setCollectionLimits(
         collectionId,
         {
-          AccountTokenOwnershipLimit,
-          SponsoredMintSize,
-          TokenLimit,
+          accountTokenOwnershipLimit,
+          sponsoredMintSize,
+          tokenLimit,
           // tslint:disable-next-line: object-literal-sort-keys
-          SponsorTimeout,
-          OwnerCanTransfer,
-          OwnerCanDestroy,
+          sponsorTimeout,
+          ownerCanTransfer,
+          ownerCanDestroy,
         },
       );
       const subTx = await submitTransactionAsync(Alice, setCollectionLim);
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -76,7 +76,7 @@
       await submitTransactionAsync(alice, changeAdminTx);
 
       const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();
-      
+
       // Transfer
       const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
       const events = await submitTransactionAsync(alice, transferTx);
@@ -85,8 +85,8 @@
 
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
-      expect(tokenBefore.Owner).to.be.deep.equal(normalizeAccountId(alice.address));
-      expect(tokenAfter.Owner).to.be.deep.equal(normalizeAccountId(bob.address));
+      expect(tokenBefore.owner).to.be.deep.equal(normalizeAccountId(alice.address));
+      expect(tokenAfter.owner).to.be.deep.equal(normalizeAccountId(bob.address));
     });
   });
 
@@ -141,7 +141,7 @@
 
       const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any)
         .map((kv: any) => kv[1].toJSON())
-        .sort((a: any, b: any) => a.ConstData.localeCompare(b.ConstData));
+        .sort((a: any, b: any) => a.constData.localeCompare(b.constData));
       expect(tokensAfter).to.be.deep.equal([
         {
           Owner: bob.address,
@@ -198,7 +198,7 @@
       expect(result.success).to.be.true;
 
       const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
-      expect(token.Owner.toString()).to.be.equal(charlie.address);
+      expect(token.owner.toString()).to.be.equal(charlie.address);
     });
   });
 
@@ -216,7 +216,7 @@
       expect(result.success).to.be.true;
 
       const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
-      expect(token.VariableData.toString()).to.be.equal('0x121314');
+      expect(token.variableData.toString()).to.be.equal('0x121314');
     });
   });
 
@@ -228,7 +228,7 @@
       const collectionId = await createCollectionExpectSuccess();
       const [contract] = await deployTransferContract(api);
       const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
-      await submitTransactionAsync(alice, changeAdminTx);      
+      await submitTransactionAsync(alice, changeAdminTx);
 
       expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
 
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -24,9 +24,9 @@
 const expect = chai.expect;
 
 interface ITokenDataType {
-  Owner: number[];
-  ConstData: number[];
-  VariableData: number[];
+  owner: number[];
+  constData: number[];
+  variableData: number[];
 }
 
 describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
@@ -46,17 +46,17 @@
       const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
       const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
 
-      expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
-      expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
-      expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Alice.address));
 
-      expect(token1Data.ConstData.toString()).to.be.equal('0x31');
-      expect(token2Data.ConstData.toString()).to.be.equal('0x32');
-      expect(token3Data.ConstData.toString()).to.be.equal('0x33');
+      expect(token1Data.constData.toString()).to.be.equal('0x31');
+      expect(token2Data.constData.toString()).to.be.equal('0x32');
+      expect(token3Data.constData.toString()).to.be.equal('0x33');
 
-      expect(token1Data.VariableData.toString()).to.be.equal('0x31');
-      expect(token2Data.VariableData.toString()).to.be.equal('0x32');
-      expect(token3Data.VariableData.toString()).to.be.equal('0x33');
+      expect(token1Data.variableData.toString()).to.be.equal('0x31');
+      expect(token2Data.variableData.toString()).to.be.equal('0x32');
+      expect(token3Data.variableData.toString()).to.be.equal('0x33');
     });
   });
 
@@ -76,7 +76,7 @@
       await submitTransactionAsync(Alice, createMultipleItemsTx);
       const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;
 
-      expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3
+      expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3
     });
   });
 
@@ -100,22 +100,22 @@
       const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
       const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
 
-      expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
-      expect(token1Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token1Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
-      expect(token2Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token2Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Alice.address));
-      expect(token3Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Alice.address));
+      expect(token3Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token1Data.ConstData.toString()).to.be.equal('0x31');
-      expect(token2Data.ConstData.toString()).to.be.equal('0x32');
-      expect(token3Data.ConstData.toString()).to.be.equal('0x33');
+      expect(token1Data.constData.toString()).to.be.equal('0x31');
+      expect(token2Data.constData.toString()).to.be.equal('0x32');
+      expect(token3Data.constData.toString()).to.be.equal('0x33');
 
-      expect(token1Data.VariableData.toString()).to.be.equal('0x31');
-      expect(token2Data.VariableData.toString()).to.be.equal('0x32');
-      expect(token3Data.VariableData.toString()).to.be.equal('0x33');
+      expect(token1Data.variableData.toString()).to.be.equal('0x31');
+      expect(token2Data.variableData.toString()).to.be.equal('0x32');
+      expect(token3Data.variableData.toString()).to.be.equal('0x33');
     });
   });
 
@@ -125,7 +125,7 @@
 
       const collectionId = await createCollectionExpectSuccess();
       await setCollectionLimitsExpectSuccess(alice, collectionId, {
-        TokenLimit: 2,
+        tokenLimit: 2,
       });
       const args = [
         { nft: ['A', 'A'] },
@@ -156,7 +156,7 @@
       const collectionId = await createCollectionExpectSuccess();
       const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
       expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
-      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 
+      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
       const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
       const createMultipleItemsTx = api.tx.nft
         .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
@@ -167,17 +167,17 @@
       const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
       const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
 
-      expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
-      expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
-      expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token1Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token2Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token3Data.owner).to.be.deep.equal(normalizeAccountId(Bob.address));
 
-      expect(token1Data.ConstData.toString()).to.be.equal('0x31');
-      expect(token2Data.ConstData.toString()).to.be.equal('0x32');
-      expect(token3Data.ConstData.toString()).to.be.equal('0x33');
+      expect(token1Data.constData.toString()).to.be.equal('0x31');
+      expect(token2Data.constData.toString()).to.be.equal('0x32');
+      expect(token3Data.constData.toString()).to.be.equal('0x33');
 
-      expect(token1Data.VariableData.toString()).to.be.equal('0x31');
-      expect(token2Data.VariableData.toString()).to.be.equal('0x32');
-      expect(token3Data.VariableData.toString()).to.be.equal('0x33');
+      expect(token1Data.variableData.toString()).to.be.equal('0x31');
+      expect(token2Data.variableData.toString()).to.be.equal('0x32');
+      expect(token3Data.variableData.toString()).to.be.equal('0x33');
     });
   });
 
@@ -186,7 +186,7 @@
       const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
       const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
       expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
-      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 
+      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
       const args = [
         {fungible: { value: 1 }},
         {fungible: { value: 2 }},
@@ -197,7 +197,7 @@
       await submitTransactionAsync(Bob, createMultipleItemsTx);
       const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;
 
-      expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3
+      expect(token1Data.value).to.be.equal(6); // 1 + 2 + 3
     });
   });
 
@@ -206,7 +206,7 @@
       const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
       const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
       expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
-      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob); 
+      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
       const args = [
         {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
         {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
@@ -221,22 +221,22 @@
       const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
       const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
 
-      expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
-      expect(token1Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token1Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token1Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
-      expect(token2Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token2Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token2Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
-      expect(token3Data.Owner[0].Fraction).to.be.equal(1);
+      expect(token3Data.owner[0].owner).to.be.deep.equal(normalizeAccountId(Bob.address));
+      expect(token3Data.owner[0].fraction).to.be.equal(1);
 
-      expect(token1Data.ConstData.toString()).to.be.equal('0x31');
-      expect(token2Data.ConstData.toString()).to.be.equal('0x32');
-      expect(token3Data.ConstData.toString()).to.be.equal('0x33');
+      expect(token1Data.constData.toString()).to.be.equal('0x31');
+      expect(token2Data.constData.toString()).to.be.equal('0x32');
+      expect(token3Data.constData.toString()).to.be.equal('0x33');
 
-      expect(token1Data.VariableData.toString()).to.be.equal('0x31');
-      expect(token2Data.VariableData.toString()).to.be.equal('0x32');
-      expect(token3Data.VariableData.toString()).to.be.equal('0x33');
+      expect(token1Data.variableData.toString()).to.be.equal('0x31');
+      expect(token2Data.variableData.toString()).to.be.equal('0x32');
+      expect(token3Data.variableData.toString()).to.be.equal('0x33');
     });
   });
 });
@@ -379,7 +379,7 @@
 
       const collectionId = await createCollectionExpectSuccess();
       await setCollectionLimitsExpectSuccess(Alice, collectionId, {
-        TokenLimit: 1,
+        tokenLimit: 1,
       });
       const args = [
         { nft: ['A', 'A'] },
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -8,9 +8,9 @@
 import chaiAsPromised from 'chai-as-promised';
 import privateKey from './substrate/privateKey';
 import { default as usingApi } from './substrate/substrate-api';
-import { createCollectionExpectSuccess, 
-  destroyCollectionExpectSuccess, 
-  destroyCollectionExpectFailure, 
+import { createCollectionExpectSuccess,
+  destroyCollectionExpectSuccess,
+  destroyCollectionExpectFailure,
   setCollectionLimitsExpectSuccess,
   addCollectionAdminExpectSuccess,
 } from './util/helpers';
@@ -67,7 +67,7 @@
   });
   it('fails when OwnerCanDestroy == false', async () => {
     const collectionId = await createCollectionExpectSuccess();
-    await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });
+    await setCollectionLimitsExpectSuccess(alice, collectionId, { ownerCanDestroy: false });
 
     await destroyCollectionExpectFailure(collectionId, '//Alice');
   });
modifiedtests/src/limits.test.tsdiffbeforeafterboth
--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -17,7 +17,7 @@
   transferExpectSuccess,
   getFreeBalance,
   waitNewBlocks,
-} from './util/helpers'; 
+} from './util/helpers';
 import { expect } from 'chai';
 
 describe('Number of tokens per address (NFT)', () => {
@@ -30,9 +30,9 @@
   });
 
   it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
-      
+
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 20 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });
     for(let i = 0; i < 10; i++){
       await createItemExpectSuccess(Alice, collectionId, 'NFT');
     }
@@ -43,7 +43,7 @@
   it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
 
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 1 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });
     await createItemExpectSuccess(Alice, collectionId, 'NFT');
     await createItemExpectFailure(Alice, collectionId, 'NFT');
     await destroyCollectionExpectSuccess(collectionId);
@@ -59,9 +59,9 @@
     });
   });
 
-  it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {   
+  it.skip('Collection limits allow greater number than chain limits, chain limits are enforced', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 20 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 20 });
     for(let i = 0; i < 10; i++){
       await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
     }
@@ -71,7 +71,7 @@
 
   it('Collection limits allow lower number than chain limits, collection limits are enforced', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 1 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 1 });
     await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
     await createItemExpectFailure(Alice, collectionId, 'ReFungible');
     await destroyCollectionExpectSuccess(collectionId);
@@ -91,9 +91,9 @@
     });
   });
 
-  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {  
+  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 7 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -117,7 +117,7 @@
   it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
 
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -152,9 +152,9 @@
     });
   });
 
-  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {  
+  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 7 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -180,7 +180,7 @@
   it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
 
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -217,9 +217,9 @@
     });
   });
 
-  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {  
+  it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 7 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 7 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -243,7 +243,7 @@
   it('Collection limits have lower timeout value than chain limits, chain limits are enforced', async () => {
 
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 1 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 1 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -278,9 +278,9 @@
     });
   });
 
-  it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {  
+  it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 0 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });
     for(let i = 0; i < 10; i++){
       await createItemExpectSuccess(Alice, collectionId, 'NFT');
     }
@@ -290,7 +290,7 @@
   it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
 
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -320,7 +320,7 @@
 
   it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'Fungible');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
@@ -349,9 +349,9 @@
     });
   });
 
-  it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {  
+  it.skip('Limits have 0 in tokens per address field, the chain limits are applied', async () => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible' }});
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { AccountTokenOwnershipLimit: 0 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { accountTokenOwnershipLimit: 0 });
     for(let i = 0; i < 10; i++){
       await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
     }
@@ -361,7 +361,7 @@
   it('Limits have 0 in sponsor timeout, no limits are applied', async () => {
 
     const collectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { SponsorTimeout: 0 });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { sponsorTimeout: 0 });
     const tokenId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible');
     await setCollectionSponsorExpectSuccess(collectionId, Alice.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Alice');
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -8,7 +8,7 @@
 import usingApi from './substrate/substrate-api';
 
 function getModuleNames(api: ApiPromise): string[] {
-  return api.runtimeMetadata.asLatest.modules.map(m => m.name.toString().toLowerCase());
+  return api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
 }
 
 // Pallets that must always be present
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -20,7 +20,7 @@
       const Alice = privateKey('//Alice');
       const Bob = privateKey('//Bob');
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(Alice.address);
+      expect(collection.owner).to.be.deep.eq(Alice.address);
       // first - add collection admin Bob
       const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
       await submitTransactionAsync(Alice, addAdminTx);
@@ -44,7 +44,7 @@
       const Bob = privateKey('//Bob');
       const Charlie = privateKey('//Charlie');
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.deep.eq(Alice.address);
+      expect(collection.owner).to.be.deep.eq(Alice.address);
       // first - add collection admin Bob
       const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
       await submitTransactionAsync(Alice, addAdminTx);
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setChainLimits.test.ts
+++ b/tests/src/setChainLimits.test.ts
@@ -25,16 +25,16 @@
       bob = privateKey('//Bob');
       dave = privateKey('//Dave');
       limits = {
-        CollectionNumbersLimit : 1,
-        AccountTokenOwnershipLimit: 1,
-        CollectionsAdminsLimit: 1,
-        CustomDataLimit: 1,
-        NftSponsorTransferTimeout: 1,
-        FungibleSponsorTransferTimeout: 1,
-        RefungibleSponsorTransferTimeout: 1,
-        OffchainSchemaLimit: 1,
-        VariableOnChainSchemaLimit: 1,
-        ConstOnChainSchemaLimit: 1,
+        collectionNumbersLimit : 1,
+        accountTokenOwnershipLimit: 1,
+        collectionsAdminsLimit: 1,
+        customDataLimit: 1,
+        nftSponsorTransferTimeout: 1,
+        fungibleSponsorTransferTimeout: 1,
+        refungibleSponsorTransferTimeout: 1,
+        offchainSchemaLimit: 1,
+        variableOnChainSchemaLimit: 1,
+        constOnChainSchemaLimit: 1,
       };
     });
   });
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -46,12 +46,12 @@
       tx = api.tx.nft.setCollectionLimits(
         collectionIdForTesting,
         {
-          AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-          SponsoredMintSize: sponsoredDataSize,
-          TokenLimit: tokenLimit,
-          SponsorTimeout: sponsorTimeout,
-          OwnerCanTransfer: true,
-          OwnerCanDestroy: true,
+          accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+          sponsoredMintSize: sponsoredDataSize,
+          tokenLimit: tokenLimit,
+          sponsorTimeout: sponsorTimeout,
+          ownerCanTransfer: true,
+          ownerCanDestroy: true,
         },
       );
       const events = await submitTransactionAsync(alice, tx);
@@ -62,12 +62,12 @@
 
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
-      expect(collectionInfo.Limits.AccountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);
-      expect(collectionInfo.Limits.SponsoredDataSize).to.be.equal(sponsoredDataSize);
-      expect(collectionInfo.Limits.TokenLimit).to.be.equal(tokenLimit);
-      expect(collectionInfo.Limits.SponsorTimeout).to.be.equal(sponsorTimeout);
-      expect(collectionInfo.Limits.OwnerCanTransfer).to.be.true;
-      expect(collectionInfo.Limits.OwnerCanDestroy).to.be.true;
+      expect(collectionInfo.limits.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);
+      expect(collectionInfo.limits.sponsoredDataSize).to.be.equal(sponsoredDataSize);
+      expect(collectionInfo.limits.tokenLimit).to.be.equal(tokenLimit);
+      expect(collectionInfo.limits.sponsorTimeout).to.be.equal(sponsorTimeout);
+      expect(collectionInfo.limits.ownerCanTransfer).to.be.true;
+      expect(collectionInfo.limits.ownerCanDestroy).to.be.true;
     });
   });
 
@@ -75,12 +75,12 @@
     await usingApi(async (api: ApiPromise) => {
 
       const collectionLimits = {
-        AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-        SponsoredMintSize: sponsoredDataSize,
-        TokenLimit: tokenLimit,
-        SponsorTimeout: sponsorTimeout,
-        OwnerCanTransfer: true,
-        OwnerCanDestroy: true,
+        accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+        sponsoredMintSize: sponsoredDataSize,
+        tokenLimit: tokenLimit,
+        sponsorTimeout: sponsorTimeout,
+        ownerCanTransfer: true,
+        ownerCanDestroy: true,
       };
 
       // The first time
@@ -103,9 +103,9 @@
 
       // tslint:disable-next-line:no-unused-expression
       expect(result1.success).to.be.true;
-      expect(collectionInfo1.Limits.TokenLimit).to.be.equal(tokenLimit);
+      expect(collectionInfo1.limits.tokenLimit).to.be.equal(tokenLimit);
       expect(result2.success).to.be.true;
-      expect(collectionInfo2.Limits.TokenLimit).to.be.equal(tokenLimit);
+      expect(collectionInfo2.limits.tokenLimit).to.be.equal(tokenLimit);
     });
   });
 
@@ -183,41 +183,41 @@
 
   it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {
     const collectionId = await createCollectionExpectSuccess();
-    await setCollectionLimitsExpectSuccess(alice, collectionId, { 
-      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-      SponsoredMintSize: sponsoredDataSize,
-      TokenLimit: tokenLimit,
-      SponsorTimeout: sponsorTimeout,
-      OwnerCanTransfer: false,
-      OwnerCanDestroy: true,
+    await setCollectionLimitsExpectSuccess(alice, collectionId, {
+      accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      sponsoredMintSize: sponsoredDataSize,
+      tokenLimit: tokenLimit,
+      sponsorTimeout: sponsorTimeout,
+      ownerCanTransfer: false,
+      ownerCanDestroy: true,
     });
-    await setCollectionLimitsExpectFailure(alice, collectionId, { 
-      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-      SponsoredMintSize: sponsoredDataSize,
-      TokenLimit: tokenLimit,
-      SponsorTimeout: sponsorTimeout,
-      OwnerCanTransfer: true,
-      OwnerCanDestroy: true,
+    await setCollectionLimitsExpectFailure(alice, collectionId, {
+      accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      sponsoredMintSize: sponsoredDataSize,
+      tokenLimit: tokenLimit,
+      sponsorTimeout: sponsorTimeout,
+      ownerCanTransfer: true,
+      ownerCanDestroy: true,
     });
   });
 
   it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {
     const collectionId = await createCollectionExpectSuccess();
     await setCollectionLimitsExpectSuccess(alice, collectionId, {
-      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-      SponsoredMintSize: sponsoredDataSize,
-      TokenLimit: tokenLimit,
-      SponsorTimeout: sponsorTimeout,
-      OwnerCanTransfer: true,
-      OwnerCanDestroy: false,
+      accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      sponsoredMintSize: sponsoredDataSize,
+      tokenLimit: tokenLimit,
+      sponsorTimeout: sponsorTimeout,
+      ownerCanTransfer: true,
+      ownerCanDestroy: false,
     });
-    await setCollectionLimitsExpectFailure(alice, collectionId, { 
-      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-      SponsoredMintSize: sponsoredDataSize,
-      TokenLimit: tokenLimit,
-      SponsorTimeout: sponsorTimeout,
-      OwnerCanTransfer: true,
-      OwnerCanDestroy: true,
+    await setCollectionLimitsExpectFailure(alice, collectionId, {
+      accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+      sponsoredMintSize: sponsoredDataSize,
+      tokenLimit: tokenLimit,
+      sponsorTimeout: sponsorTimeout,
+      ownerCanTransfer: true,
+      ownerCanDestroy: true,
     });
   });
 
@@ -226,19 +226,19 @@
 
       const collectionId = await createCollectionExpectSuccess();
       const collectionLimits = {
-        AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
-        SponsoredMintSize: sponsoredDataSize,
-        TokenLimit: tokenLimit,
-        SponsorTimeout: sponsorTimeout,
-        OwnerCanTransfer: true,
-        OwnerCanDestroy: true,
+        accountTokenOwnershipLimit: accountTokenOwnershipLimit,
+        sponsoredMintSize: sponsoredDataSize,
+        tokenLimit: tokenLimit,
+        sponsorTimeout: sponsorTimeout,
+        ownerCanTransfer: true,
+        ownerCanDestroy: true,
       };
 
       // The first time
       await setCollectionLimitsExpectSuccess(alice, collectionId, collectionLimits);
 
       // The second time - higher token limit
-      collectionLimits.TokenLimit += 1;
+      collectionLimits.tokenLimit += 1;
       await setCollectionLimitsExpectFailure(alice, collectionId, collectionLimits);
     });
   });
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
--- a/tests/src/setConstOnChainSchema.test.ts
+++ b/tests/src/setConstOnChainSchema.test.ts
@@ -38,7 +38,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
       await submitTransactionAsync(Alice, setShema);
     });
@@ -48,7 +48,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
       const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
       await submitTransactionAsync(Bob, setShema);
@@ -61,7 +61,7 @@
       const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
       await submitTransactionAsync(Alice, setShema);
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);
+      expect(collection.constOnChainSchema.toString()).to.be.eq(Shema);
 
     });
   });
@@ -99,7 +99,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
       await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;
     });
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
--- a/tests/src/setOffchainSchema.test.ts
+++ b/tests/src/setOffchainSchema.test.ts
@@ -39,7 +39,7 @@
     await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
     const collection = await queryCollectionExpectSuccess(collectionId);
 
-    expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+    expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
   });
 
   it('execute setOffchainSchema (collection admin), verify data was set', async () => {
@@ -48,7 +48,7 @@
     await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
     const collection = await queryCollectionExpectSuccess(collectionId);
 
-    expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
+    expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
   });
 });
 
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -66,7 +66,7 @@
       // tslint:disable-next-line:no-unused-expression
       expect(collectionInfo).to.be.exist;
       // tslint:disable-next-line:no-unused-expression
-      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');
+      expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');
     });
   });
 });
@@ -92,7 +92,7 @@
       // tslint:disable-next-line:no-unused-expression
       expect(collectionInfo).to.be.exist;
       // tslint:disable-next-line:no-unused-expression
-      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');
+      expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');
     });
   });
 
@@ -107,7 +107,7 @@
       // tslint:disable-next-line:no-unused-expression
       expect(collectionInfo).to.be.exist;
       // tslint:disable-next-line:no-unused-expression
-      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');
+      expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('ImageURL');
     });
   });
 });
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -45,7 +45,7 @@
     await usingApi(async api => {
       const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
 
-      expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
+      expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));
     });
   });
 });
@@ -76,7 +76,7 @@
     await usingApi(async api => {
       const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
 
-      expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
+      expect(Array.from(item.variableData)).to.deep.equal(Array.from(data));
     });
   });
 });
modifiedtests/src/setVariableMetadataSponsoringRateLimit.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableMetadataSponsoringRateLimit.test.ts
+++ b/tests/src/setVariableMetadataSponsoringRateLimit.test.ts
@@ -33,7 +33,7 @@
     await setCollectionSponsorExpectSuccess(collectionId, alice.address);
     await confirmSponsorshipExpectSuccess(collectionId);
     await setCollectionLimitsExpectSuccess(alice, collectionId, {
-      SponsoredDataRateLimit: 0,
+      sponsoredDataRateLimit: 0,
     });
 
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);
@@ -46,7 +46,7 @@
     await setCollectionSponsorExpectSuccess(collectionId, alice.address);
     await confirmSponsorshipExpectSuccess(collectionId);
     await setCollectionLimitsExpectSuccess(alice, collectionId, {
-      SponsoredDataRateLimit: 10,
+      sponsoredDataRateLimit: 10,
     });
 
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);
@@ -59,8 +59,8 @@
     await setCollectionSponsorExpectSuccess(collectionId, alice.address);
     await confirmSponsorshipExpectSuccess(collectionId);
     await setCollectionLimitsExpectSuccess(alice, collectionId, {
-      SponsoredDataRateLimit: 0,
-      SponsoredDataSize: 1,
+      sponsoredDataRateLimit: 0,
+      sponsoredDataSize: 1,
     });
     const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', userWithNoBalance.address);
 
modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -38,7 +38,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
       await submitTransactionAsync(Alice, setSchema);
     });
@@ -50,7 +50,7 @@
       const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
       await submitTransactionAsync(Alice, setSchema);
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
+      expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);
 
     });
   });
@@ -62,7 +62,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
       const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
       await submitTransactionAsync(Bob, setSchema);
@@ -76,7 +76,7 @@
       const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
       await submitTransactionAsync(Bob, setSchema);
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
+      expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);
 
     });
   });
@@ -114,7 +114,7 @@
     await usingApi(async (api) => {
       const collectionId = await createCollectionExpectSuccess();
       const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
-      expect(collection.Owner).to.be.eq(Alice.address);
+      expect(collection.owner).to.be.eq(Alice.address);
       const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
       await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;
     });
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -11,12 +11,11 @@
 import config from '../config';
 import promisifySubstrate from './promisify-substrate';
 import { ApiOptions, SubmittableExtrinsic, ApiTypes } from '@polkadot/api/types';
-import rtt from '../../../runtime_types.json';
 
 function defaultApiOptions(): ApiOptions {
   const wsProvider = new WsProvider(config.substrateUrl);
   return {
-    provider: wsProvider, types: rtt, signedExtensions: {
+    provider: wsProvider, signedExtensions: {
       ContractHelpers: {
         extrinsic: {},
         payload: {},
@@ -30,7 +29,7 @@
   const api: ApiPromise = new ApiPromise(settings);
   let result: T = null as unknown as T;
 
-  // TODO: Remove, this is temporary: Filter unneeded API output 
+  // TODO: Remove, this is temporary: Filter unneeded API output
   // (Jaco promised it will be removed in the next version)
   const consoleErr = console.error;
   const consoleLog = console.log;
@@ -41,7 +40,7 @@
       consoleErr(message);
       return;
     }
-    if (!message.includes('StorageChangeSet:: WebSocket is not connected') && 
+    if (!message.includes('StorageChangeSet:: WebSocket is not connected') &&
         !message.includes('2021-') &&
         !message.includes('StorageChangeSet:: Normal connection closure'))
       consoleErr(message);
@@ -79,7 +78,7 @@
   }
   if (status.isBroadcast) {
     return TransactionStatus.NotReady;
-  } 
+  }
   if (status.isInBlock || status.isFinalized) {
     if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {
       return TransactionStatus.Fail;
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -248,7 +248,7 @@
       const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
       await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
       await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);
-      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      
+      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
     });
   });
   it( 'transferFrom burnt token before approve Fungible', async () => {
@@ -258,9 +258,9 @@
       await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
       await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
       await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
-          
+
     });
-  }); 
+  });
   it( 'transferFrom burnt token before approve ReFungible', async () => {
     await usingApi(async () => {
       const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
@@ -268,10 +268,10 @@
       await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
       await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
       await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
-          
+
     });
   });
-  
+
   it( 'transferFrom burnt token after approve NFT', async () => {
     await usingApi(async () => {
       // nft
@@ -279,7 +279,7 @@
       const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
       await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
       await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
-      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      
+      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
     });
   });
   it( 'transferFrom burnt token after approve Fungible', async () => {
@@ -289,9 +289,9 @@
       await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
       await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
       await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
-          
+
     });
-  }); 
+  });
   it( 'transferFrom burnt token after approve ReFungible', async () => {
     await usingApi(async () => {
       const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
@@ -299,14 +299,14 @@
       await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
       await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
       await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
-          
+
     });
   });
 
   it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
     const collectionId = await createCollectionExpectSuccess();
     const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
-    await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });
+    await setCollectionLimitsExpectSuccess(Alice, collectionId, { ownerCanTransfer: false });
 
     await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);
   });
modifiedtests/src/types.tsdiffbeforeafterboth
--- a/tests/src/types.ts
+++ b/tests/src/types.ts
@@ -6,29 +6,29 @@
 import BN from 'bn.js';
 
 export interface ICollectionInterface {
-  Access: string;
+  access: string;
   id: number;
-  DecimalPoints: BN;
+  decimalPoints: BN;
   // constOnChainSchema
-  Description: [BN, BN]; // utf16
+  description: [BN, BN]; // utf16
   isReFungible: boolean;
-  Limits: {
-    AccountTokenOwnershipLimit: number;
-    SponsoredDataSize: number;
-    SponsoredDataRateLimit?: number,
-    TokenLimit: number;
-    SponsorTimeout: number;
-    OwnerCanTransfer: boolean;
-    OwnerCanDestroy: boolean;
+  limits: {
+    accountTokenOwnershipLimit: number;
+    sponsoredDataSize: number;
+    sponsoredDataRateLimit?: number,
+    tokenLimit: number;
+    sponsorTimeout: number;
+    ownerCanTransfer: boolean;
+    ownerCanDestroy: boolean;
   };
-  MintMode: boolean;
-  Mode: {
-    Nft: null;
+  mintMode: boolean;
+  mode: {
+    nft: null;
   };
-  Name: [BN, BN]; // utf16
-  OffchainSchema: [Uint8Array];
-  Owner: [Uint8Array];
-  SchemaVersion: string;
+  name: [BN, BN]; // utf16
+  offchainSchema: [Uint8Array];
+  owner: [Uint8Array];
+  schemaVersion: string;
   // prefix
   // sponsor
   // tokenPrefix
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 type { AccountId, EventRecord } from '@polkadot/types/interfaces';8import { IKeyringPair } from '@polkadot/types/types';9import { evmToAddress } from '@polkadot/util-crypto';10import { BigNumber } from 'bignumber.js';11import BN from 'bn.js';12import chai from 'chai';13import chaiAsPromised from 'chai-as-promised';14import { alicesPublicKey } from '../accounts';15import privateKey from '../substrate/privateKey';16import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';17import { ICollectionInterface } from '../types';18import { hexToStr, strToUTF16, utf16ToStr } from './util';1920chai.use(chaiAsPromised);21const expect = chai.expect;2223export type CrossAccountId = {24  substrate: string,25} | {26  ethereum: string,27};28export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {29  if (typeof input === 'string')30    return { substrate: input };31  if ('address' in input) {32    return { substrate: input.address };33  }34  if ('ethereum' in input) {35    input.ethereum = input.ethereum.toLowerCase();36    return input;37  }38  if ('substrate' in input) {39    return input;40  }4142  // AccountId43  return {substrate: input.toString()};44}45export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {46  input = normalizeAccountId(input);47  if ('substrate' in input) {48    return input.substrate;49  } else {50    return evmToAddress(input.ethereum);51  }52}5354export const U128_MAX = (1n << 128n) - 1n;5556const MICROUNIQUE = 1_000_000_000n;57const MILLIUNIQUE = 1_000n * MICROUNIQUE;58const CENTIUNIQUE = 10n * MILLIUNIQUE;59export const UNIQUE = 100n * CENTIUNIQUE;6061type GenericResult = {62  success: boolean,63};6465interface CreateCollectionResult {66  success: boolean;67  collectionId: number;68}6970interface CreateItemResult {71  success: boolean;72  collectionId: number;73  itemId: number;74  recipient?: CrossAccountId;75}7677interface TransferResult {78  success: boolean;79  collectionId: number;80  itemId: number;81  sender?: CrossAccountId;82  recipient?: CrossAccountId;83  value: bigint;84}8586interface IReFungibleOwner {87  Fraction: BN;88  Owner: number[];89}9091interface ITokenDataType {92  Owner: IKeyringPair;93  ConstData: number[];94  VariableData: number[];95}9697interface IGetMessage {98  checkMsgNftMethod: string;99  checkMsgTrsMethod: string;100  checkMsgSysMethod: string;101}102103export interface IFungibleTokenDataType {104  Value: number;105}106107export interface IChainLimits {108  CollectionNumbersLimit: number;109	AccountTokenOwnershipLimit: number;110	CollectionsAdminsLimit: number;111	CustomDataLimit: number;112	NftSponsorTransferTimeout: number;113	FungibleSponsorTransferTimeout: number;114	RefungibleSponsorTransferTimeout: number;115	OffchainSchemaLimit: number;116	VariableOnChainSchemaLimit: number;117	ConstOnChainSchemaLimit: number;118}119120export interface IReFungibleTokenDataType {121  Owner: IReFungibleOwner[];122  ConstData: number[];123  VariableData: number[];124}125126export function nftEventMessage(events: EventRecord[]): IGetMessage {127  let checkMsgNftMethod = '';128  let checkMsgTrsMethod = '';129  let checkMsgSysMethod = '';130  events.forEach(({ event: { method, section } }) => {131    if (section === 'nft') {132      checkMsgNftMethod = method;133    } else if (section === 'treasury') {134      checkMsgTrsMethod = method;135    } else if (section === 'system') {136      checkMsgSysMethod = method;137    } else { return null; }138  });139  const result: IGetMessage = {140    checkMsgNftMethod,141    checkMsgTrsMethod,142    checkMsgSysMethod,143  };144  return result;145}146147export function getGenericResult(events: EventRecord[]): GenericResult {148  const result: GenericResult = {149    success: false,150  };151  events.forEach(({ event: { method } }) => {152    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);153    if (method === 'ExtrinsicSuccess') {154      result.success = true;155    }156  });157  return result;158}159160161162export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {163  let success = false;164  let collectionId = 0;165  events.forEach(({ event: { data, method, section } }) => {166    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);167    if (method == 'ExtrinsicSuccess') {168      success = true;169    } else if ((section == 'nft') && (method == 'CollectionCreated')) {170      collectionId = parseInt(data[0].toString());171    }172  });173  const result: CreateCollectionResult = {174    success,175    collectionId,176  };177  return result;178}179180export function getCreateItemResult(events: EventRecord[]): CreateItemResult {181  let success = false;182  let collectionId = 0;183  let itemId = 0;184  let recipient;185  events.forEach(({ event: { data, method, section } }) => {186    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);187    if (method == 'ExtrinsicSuccess') {188      success = true;189    } else if ((section == 'nft') && (method == 'ItemCreated')) {190      collectionId = parseInt(data[0].toString());191      itemId = parseInt(data[1].toString());192      recipient = data[2].toJSON();193    }194  });195  const result: CreateItemResult = {196    success,197    collectionId,198    itemId,199    recipient,200  };201  return result;202}203204export function getTransferResult(events: EventRecord[]): TransferResult {205  const result: TransferResult = {206    success: false,207    collectionId: 0,208    itemId: 0,209    value: 0n,210  };211212  events.forEach(({ event: { data, method, section } }) => {213    if (method === 'ExtrinsicSuccess') {214      result.success = true;215    } else if (section === 'nft' && method === 'Transfer') {216      result.collectionId = +data[0].toString();217      result.itemId = +data[1].toString();218      result.sender = data[2].toJSON() as CrossAccountId;219      result.recipient = data[3].toJSON() as CrossAccountId;220      result.value = BigInt(data[4].toString());221    }222  });223224  return result;225}226227interface Nft {228  type: 'NFT';229}230231interface Fungible {232  type: 'Fungible';233  decimalPoints: number;234}235236interface ReFungible {237  type: 'ReFungible';238}239240type CollectionMode = Nft | Fungible | ReFungible;241242export type CreateCollectionParams = {243  mode: CollectionMode,244  name: string,245  description: string,246  tokenPrefix: string,247};248249const defaultCreateCollectionParams: CreateCollectionParams = {250  description: 'description',251  mode: { type: 'NFT' },252  name: 'name',253  tokenPrefix: 'prefix',254};255256export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {257  const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };258259  let collectionId = 0;260  await usingApi(async (api) => {261    // Get number of collections before the transaction262    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);263264    // Run the CreateCollection transaction265    const alicePrivateKey = privateKey('//Alice');266267    let modeprm = {};268    if (mode.type === 'NFT') {269      modeprm = { nft: null };270    } else if (mode.type === 'Fungible') {271      modeprm = { fungible: mode.decimalPoints };272    } else if (mode.type === 'ReFungible') {273      modeprm = { refungible: null };274    }275276    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);277    const events = await submitTransactionAsync(alicePrivateKey, tx);278    const result = getCreateCollectionResult(events);279280    // Get number of collections after the transaction281    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);282283    // Get the collection284    const collection: any = (await api.query.nft.collectionById(result.collectionId) as any).toJSON();285286    // What to expect287    // tslint:disable-next-line:no-unused-expression288    expect(result.success).to.be.true;289    expect(result.collectionId).to.be.equal(BcollectionCount);290    // tslint:disable-next-line:no-unused-expression291    expect(collection).to.be.not.null;292    expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');293    expect(collection.Owner).to.be.equal(toSubstrateAddress(alicesPublicKey));294    expect(utf16ToStr(collection.Name)).to.be.equal(name);295    expect(utf16ToStr(collection.Description)).to.be.equal(description);296    expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);297298    collectionId = result.collectionId;299  });300301  return collectionId;302}303304export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {305  const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };306307  let modeprm = {};308  if (mode.type === 'NFT') {309    modeprm = { nft: null };310  } else if (mode.type === 'Fungible') {311    modeprm = { fungible: mode.decimalPoints };312  } else if (mode.type === 'ReFungible') {313    modeprm = { refungible: null };314  }315316  await usingApi(async (api) => {317    // Get number of collections before the transaction318    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());319320    // Run the CreateCollection transaction321    const alicePrivateKey = privateKey('//Alice');322    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);323    const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;324    const result = getCreateCollectionResult(events);325326    // Get number of collections after the transaction327    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());328329    // What to expect330    // tslint:disable-next-line:no-unused-expression331    expect(result.success).to.be.false;332    expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');333  });334}335336export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {337  let bal = new BigNumber(0);338  let unused;339  do {340    const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;341    const keyring = new Keyring({ type: 'sr25519' });342    unused = keyring.addFromUri(`//${randomSeed}`);343    bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());344  } while (bal.toFixed() != '0');345  return unused;346}347348export async function getAllowance(collectionId: number, tokenId: number, owner: string, approved: string) {349  return await usingApi(async (api) => {350    const bn = await api.query.nft.allowances(collectionId, [tokenId, owner, approved]) as unknown as BN;351    return BigInt(bn.toString());352  });353}354355export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {356  return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));357}358359export async function findNotExistingCollection(api: ApiPromise): Promise<number> {360  const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;361  const newCollection: number = totalNumber + 1;362  return newCollection;363}364365function getDestroyResult(events: EventRecord[]): boolean {366  let success = false;367  events.forEach(({ event: { method } }) => {368    if (method == 'ExtrinsicSuccess') {369      success = true;370    }371  });372  return success;373}374375export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {376  await usingApi(async (api) => {377    // Run the DestroyCollection transaction378    const alicePrivateKey = privateKey(senderSeed);379    const tx = api.tx.nft.destroyCollection(collectionId);380    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;381  });382}383384export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {385  await usingApi(async (api) => {386    // Run the DestroyCollection transaction387    const alicePrivateKey = privateKey(senderSeed);388    const tx = api.tx.nft.destroyCollection(collectionId);389    const events = await submitTransactionAsync(alicePrivateKey, tx);390    const result = getDestroyResult(events);391392    // Get the collection393    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();394395    // What to expect396    expect(result).to.be.true;397    expect(collection).to.be.null;398  });399}400401export async function queryCollectionLimits(collectionId: number) {402  return await usingApi(async (api) => {403    return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).Limits;404  });405}406407export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {408  await usingApi(async (api) => {409    const oldLimits = await queryCollectionLimits(collectionId);410    const newLimits = { ...oldLimits as any, ...limits };411    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);412    const events = await submitTransactionAsync(sender, tx);413    const result = getGenericResult(events);414415    expect(result.success).to.be.true;416  });417}418419export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {420  await usingApi(async (api) => {421    const oldLimits = await queryCollectionLimits(collectionId);422    const newLimits = { ...oldLimits as any, ...limits };423    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);424    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;425    const result = getGenericResult(events);426427    expect(result.success).to.be.false;428  });429}430431export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {432  await usingApi(async (api) => {433434    // Run the transaction435    const senderPrivateKey = privateKey(sender);436    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);437    const events = await submitTransactionAsync(senderPrivateKey, tx);438    const result = getGenericResult(events);439440    // Get the collection441    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();442443    // What to expect444    expect(result.success).to.be.true;445    expect(collection.Sponsorship).to.deep.equal({446      unconfirmed: sponsor,447    });448  });449}450451export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {452  await usingApi(async (api) => {453454    // Run the transaction455    const alicePrivateKey = privateKey(sender);456    const tx = api.tx.nft.removeCollectionSponsor(collectionId);457    const events = await submitTransactionAsync(alicePrivateKey, tx);458    const result = getGenericResult(events);459460    // Get the collection461    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();462463    // What to expect464    expect(result.success).to.be.true;465    expect(collection.Sponsorship).to.be.deep.equal({ disabled: null });466  });467}468469export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {470  await usingApi(async (api) => {471472    // Run the transaction473    const alicePrivateKey = privateKey(senderSeed);474    const tx = api.tx.nft.removeCollectionSponsor(collectionId);475    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;476  });477}478479export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {480  await usingApi(async (api) => {481482    // Run the transaction483    const alicePrivateKey = privateKey(senderSeed);484    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);485    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;486  });487}488489export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {490  await usingApi(async (api) => {491492    // Run the transaction493    const sender = privateKey(senderSeed);494    const tx = api.tx.nft.confirmSponsorship(collectionId);495    const events = await submitTransactionAsync(sender, tx);496    const result = getGenericResult(events);497498    // Get the collection499    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();500501    // What to expect502    expect(result.success).to.be.true;503    expect(collection.Sponsorship).to.be.deep.equal({504      confirmed: sender.address,505    });506  });507}508509510export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {511  await usingApi(async (api) => {512513    // Run the transaction514    const sender = privateKey(senderSeed);515    const tx = api.tx.nft.confirmSponsorship(collectionId);516    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;517  });518}519520export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {521522  await usingApi(async (api) => {523    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);524    const events = await submitTransactionAsync(sender, tx);525    const result = getGenericResult(events);526527    expect(result.success).to.be.true;528  });529}530531export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {532533  await usingApi(async (api) => {534    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);535    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;536    const result = getGenericResult(events);537538    expect(result.success).to.be.false;539  });540}541542export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {543  await usingApi(async (api) => {544    const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);545    const events = await submitTransactionAsync(sender, tx);546    const result = getGenericResult(events);547548    expect(result.success).to.be.true;549  });550}551552export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {553  await usingApi(async (api) => {554    const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);555    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;556    const result = getGenericResult(events);557558    expect(result.success).to.be.false;559  });560}561562export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {563564  await usingApi(async (api) => {565566    const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);567    const events = await submitTransactionAsync(sender, tx);568    const result = getGenericResult(events);569570    expect(result.success).to.be.true;571  });572}573574export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {575576  await usingApi(async (api) => {577578    const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);579    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;580    const result = getGenericResult(events);581582    expect(result.success).to.be.false;583  });584}585586export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {587  await usingApi(async (api) => {588    const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);589    const events = await submitTransactionAsync(sender, tx);590    const result = getGenericResult(events);591592    expect(result.success).to.be.true;593  });594}595596export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {597  await usingApi(async (api) => {598    const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);599    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;600    const result = getGenericResult(events);601602    expect(result.success).to.be.false;603  });604}605606export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {607  await usingApi(async (api) => {608    const tx = api.tx.nft.toggleContractWhiteList(contractAddress, value);609    const events = await submitTransactionAsync(sender, tx);610    const result = getGenericResult(events);611612    expect(result.success).to.be.true;613  });614}615616export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) {617  let whitelisted = false;618  await usingApi(async (api) => {619    whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean;620  });621  return whitelisted;622}623624export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {625  await usingApi(async (api) => {626    const tx = api.tx.nft.addToContractWhiteList(contractAddress.toString(), user.toString());627    const events = await submitTransactionAsync(sender, tx);628    const result = getGenericResult(events);629630    expect(result.success).to.be.true;631  });632}633634export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {635  await usingApi(async (api) => {636    const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());637    const events = await submitTransactionAsync(sender, tx);638    const result = getGenericResult(events);639640    expect(result.success).to.be.true;641  });642}643644export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {645  await usingApi(async (api) => {646    const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());647    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;648    const result = getGenericResult(events);649650    expect(result.success).to.be.false;651  });652}653654export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {655  await usingApi(async (api) => {656    const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));657    const events = await submitTransactionAsync(sender, tx);658    const result = getGenericResult(events);659660    expect(result.success).to.be.true;661  });662}663664export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {665  await usingApi(async (api) => {666    const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));667    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;668  });669}670671export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {672  await usingApi(async (api) => {673    const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));674    const events = await submitTransactionAsync(sender, tx);675    const result = getGenericResult(events);676677    expect(result.success).to.be.true;678  });679}680681export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {682  await usingApi(async (api) => {683    const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));684    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;685  });686}687688export interface CreateFungibleData {689  readonly Value: bigint;690}691692export interface CreateReFungibleData { }693export interface CreateNftData { }694695export type CreateItemData = {696  NFT: CreateNftData;697} | {698  Fungible: CreateFungibleData;699} | {700  ReFungible: CreateReFungibleData;701};702703export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {704  await usingApi(async (api) => {705    const tx = api.tx.nft.burnItem(collectionId, tokenId, value);706    const events = await submitTransactionAsync(owner, tx);707    const result = getGenericResult(events);708    // Get the item709    const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();710    // What to expect711    // tslint:disable-next-line:no-unused-expression712    expect(result.success).to.be.true;713    // tslint:disable-next-line:no-unused-expression714    expect(item).to.be.null;715  });716}717718export async function719approveExpectSuccess(720  collectionId: number,721  tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1,722) {723  await usingApi(async (api: ApiPromise) => {724    approved = normalizeAccountId(approved);725    const allowanceBefore =726      await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;727    const approveNftTx = api.tx.nft.approve(approved, collectionId, tokenId, amount);728    const events = await submitTransactionAsync(owner, approveNftTx);729    const result = getCreateItemResult(events);730    // tslint:disable-next-line:no-unused-expression731    expect(result.success).to.be.true;732    const allowanceAfter =733      await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;734    expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());735  });736}737738export async function739transferFromExpectSuccess(740  collectionId: number,741  tokenId: number,742  accountApproved: IKeyringPair,743  accountFrom: IKeyringPair | CrossAccountId,744  accountTo: IKeyringPair | CrossAccountId,745  value: number | bigint = 1,746  type = 'NFT',747) {748  await usingApi(async (api: ApiPromise) => {749    const to = normalizeAccountId(accountTo);750    let balanceBefore = new BN(0);751    if (type === 'Fungible') {752      balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;753    }754    const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);755    const events = await submitTransactionAsync(accountApproved, transferFromTx);756    const result = getCreateItemResult(events);757    // tslint:disable-next-line:no-unused-expression758    expect(result.success).to.be.true;759    if (type === 'NFT') {760      const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON() as ITokenDataType;761      expect(nftItemData.Owner).to.be.deep.equal(to);762    }763    if (type === 'Fungible') {764      const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).Value as unknown as BN;765      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());766    }767    if (type === 'ReFungible') {768      const nftItemData =769        (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).toJSON() as IReFungibleTokenDataType;770      expect(nftItemData.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(to));771      expect(nftItemData.Owner[0].Fraction).to.be.equal(value);772    }773  });774}775776export async function777transferFromExpectFail(778  collectionId: number,779  tokenId: number,780  accountApproved: IKeyringPair,781  accountFrom: IKeyringPair,782  accountTo: IKeyringPair,783  value: number | bigint = 1,784) {785  await usingApi(async (api: ApiPromise) => {786    const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);787    const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;788    const result = getCreateCollectionResult(events);789    // tslint:disable-next-line:no-unused-expression790    expect(result.success).to.be.false;791  });792}793794/* eslint no-async-promise-executor: "off" */795async function getBlockNumber(api: ApiPromise): Promise<number> {796  return new Promise<number>(async (resolve) => {797    const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {798      unsubscribe();799      resolve(head.number.toNumber());800    });801  });802}803804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {805  await usingApi(async (api) => {806    const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));807    const events = await submitTransactionAsync(sender, changeAdminTx);808    const result = getCreateCollectionResult(events);809    expect(result.success).to.be.true;810  });811}812813export async function814getFreeBalance(account: IKeyringPair) : Promise<BigNumber>815{816  let balance = new BigNumber(0) ;817  await usingApi(async (api) => { 818    balance = new BigNumber((await api.query.system.account(account.address)).data.free.toString());  819  });820821  return balance;822}823824export async function825scheduleTransferExpectSuccess(826  collectionId: number,827  tokenId: number,828  sender: IKeyringPair,829  recipient: IKeyringPair,830  value: number | bigint = 1,831  blockTimeMs: number,832  blockSchedule: number,833) {834  await usingApi(async (api: ApiPromise) => {835    const blockNumber: number | undefined = await getBlockNumber(api);836    const expectedBlockNumber = blockNumber + blockSchedule;837838    expect(blockNumber).to.be.greaterThan(0);839    const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);840    const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);841842    await submitTransactionAsync(sender, scheduleTx);843844    const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());845846    const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;847    expect(toSubstrateAddress(nftItemDataBefore.Owner)).to.be.equal(sender.address);848849    // sleep for 4 blocks850    await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));851852    const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());853854    const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;855    expect(toSubstrateAddress(nftItemData.Owner)).to.be.equal(recipient.address);856    expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());857  });858}859860861export async function862transferExpectSuccess(863  collectionId: number,864  tokenId: number,865  sender: IKeyringPair,866  recipient: IKeyringPair | CrossAccountId,867  value: number | bigint = 1,868  type = 'NFT',869) {870  await usingApi(async (api: ApiPromise) => {871    const to = normalizeAccountId(recipient);872873    let balanceBefore = new BN(0);874    if (type === 'Fungible') {875      balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;876    }877    const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);878    const events = await submitTransactionAsync(sender, transferTx);879    const result = getTransferResult(events);880    // tslint:disable-next-line:no-unused-expression881    expect(result.success).to.be.true;882    expect(result.collectionId).to.be.equal(collectionId);883    expect(result.itemId).to.be.equal(tokenId);884    expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));885    expect(result.recipient).to.be.deep.equal(to);886    expect(result.value.toString()).to.be.equal(value.toString());887    if (type === 'NFT') {888      const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;889      expect(nftItemData.Owner).to.be.deep.equal(to);890    }891    if (type === 'Fungible') {892      const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).Value as unknown as BN;893      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());894    }895    if (type === 'ReFungible') {896      const nftItemData =897        (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;898      const expectedOwner = toSubstrateAddress(to);899      const ownerIndex = nftItemData.Owner.findIndex(v => toSubstrateAddress(v.Owner as any as string) == expectedOwner);900      expect(ownerIndex).to.not.equal(-1);901      expect(nftItemData.Owner[ownerIndex].Owner).to.be.deep.equal(normalizeAccountId(to));902      expect(nftItemData.Owner[ownerIndex].Fraction).to.be.greaterThanOrEqual(value as number);903    }904  });905}906907export async function908transferExpectFailure(909  collectionId: number,910  tokenId: number,911  sender: IKeyringPair,912  recipient: IKeyringPair,913  value: number | bigint = 1,914) {915  await usingApi(async (api: ApiPromise) => {916    const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);917    const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;918    if (events && Array.isArray(events)) {919      const result = getCreateCollectionResult(events);920      // tslint:disable-next-line:no-unused-expression921      expect(result.success).to.be.false;922    }923  });924}925926export async function927approveExpectFail(928  collectionId: number,929  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,930) {931  await usingApi(async (api: ApiPromise) => {932    const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);933    const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;934    const result = getCreateCollectionResult(events);935    // tslint:disable-next-line:no-unused-expression936    expect(result.success).to.be.false;937  });938}939940export async function getFungibleBalance(941  collectionId: number,942  owner: string,943) {944  return await usingApi(async (api) => {945    const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { Value: string };946    return BigInt(response.Value);947  });948}949950export async function createFungibleItemExpectSuccess(951  sender: IKeyringPair,952  collectionId: number,953  data: CreateFungibleData,954  owner: CrossAccountId | string = sender.address,955) {956  return await usingApi(async (api) => {957    const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), { Fungible: data });958959    const events = await submitTransactionAsync(sender, tx);960    const result = getCreateItemResult(events);961962    expect(result.success).to.be.true;963    return result.itemId;964  });965}966967export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {968  let newItemId = 0;969  await usingApi(async (api) => {970    const to = normalizeAccountId(owner);971    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);972    const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();973    const AItemBalance = new BigNumber(Aitem.Value);974975    let tx;976    if (createMode === 'Fungible') {977      const createData = { fungible: { value: 10 } };978      tx = api.tx.nft.createItem(collectionId, to, createData);979    } else if (createMode === 'ReFungible') {980      const createData = { refungible: { const_data: [], variable_data: [], pieces: 100 } };981      tx = api.tx.nft.createItem(collectionId, to, createData);982    } else {983      const createData = { nft: { const_data: [], variable_data: [] } };984      tx = api.tx.nft.createItem(collectionId, to, createData);985    }986987    const events = await submitTransactionAsync(sender, tx);988    const result = getCreateItemResult(events);989990    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);991    const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();992    const BItemBalance = new BigNumber(Bitem.Value);993994    // What to expect995    // tslint:disable-next-line:no-unused-expression996    expect(result.success).to.be.true;997    if (createMode === 'Fungible') {998      expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);999    } else {1000      expect(BItemCount).to.be.equal(AItemCount + 1);1001    }1002    expect(collectionId).to.be.equal(result.collectionId);1003    expect(BItemCount.toString()).to.be.equal(result.itemId.toString());1004    expect(to).to.be.deep.equal(result.recipient);1005    newItemId = result.itemId;1006  });1007  return newItemId;1008}10091010export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {1011  await usingApi(async (api) => {1012    const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);10131014    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1015    const result = getCreateItemResult(events);10161017    expect(result.success).to.be.false;1018  });1019}10201021export async function setPublicAccessModeExpectSuccess(1022  sender: IKeyringPair, collectionId: number,1023  accessMode: 'Normal' | 'WhiteList',1024) {1025  await usingApi(async (api) => {10261027    // Run the transaction1028    const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1029    const events = await submitTransactionAsync(sender, tx);1030    const result = getGenericResult(events);10311032    // Get the collection1033    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();10341035    // What to expect1036    // tslint:disable-next-line:no-unused-expression1037    expect(result.success).to.be.true;1038    expect(collection.Access).to.be.equal(accessMode);1039  });1040}10411042export async function setPublicAccessModeExpectFail(1043  sender: IKeyringPair, collectionId: number,1044  accessMode: 'Normal' | 'WhiteList',1045) {1046  await usingApi(async (api) => {10471048    // Run the transaction1049    const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1050    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1051    const result = getGenericResult(events);10521053    // What to expect1054    // tslint:disable-next-line:no-unused-expression1055    expect(result.success).to.be.false;1056  });1057}10581059export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1060  await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');1061}10621063export async function enableWhiteListExpectFail(sender: IKeyringPair, collectionId: number) {1064  await setPublicAccessModeExpectFail(sender, collectionId, 'WhiteList');1065}10661067export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1068  await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1069}10701071export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1072  await usingApi(async (api) => {10731074    // Run the transaction1075    const tx = api.tx.nft.setMintPermission(collectionId, enabled);1076    const events = await submitTransactionAsync(sender, tx);1077    const result = getGenericResult(events);10781079    // Get the collection1080    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();10811082    // What to expect1083    // tslint:disable-next-line:no-unused-expression1084    expect(result.success).to.be.true;1085    expect(collection.MintMode).to.be.equal(enabled);1086  });1087}10881089export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1090  await setMintPermissionExpectSuccess(sender, collectionId, true);1091}10921093export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1094  await usingApi(async (api) => {1095    // Run the transaction1096    const tx = api.tx.nft.setMintPermission(collectionId, enabled);1097    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1098    const result = getCreateCollectionResult(events);1099    // tslint:disable-next-line:no-unused-expression1100    expect(result.success).to.be.false;1101  });1102}11031104export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1105  await usingApi(async (api) => {1106    // Run the transaction1107    const tx = api.tx.nft.setChainLimits(limits);1108    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1109    const result = getCreateCollectionResult(events);1110    // tslint:disable-next-line:no-unused-expression1111    expect(result.success).to.be.false;1112  });1113}11141115export async function isWhitelisted(collectionId: number, address: string) {1116  let whitelisted = false;1117  await usingApi(async (api) => {1118    whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;1119  });1120  return whitelisted;1121}11221123export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1124  await usingApi(async (api) => {11251126    const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();11271128    // Run the transaction1129    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1130    const events = await submitTransactionAsync(sender, tx);1131    const result = getGenericResult(events);11321133    const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();11341135    // What to expect1136    // tslint:disable-next-line:no-unused-expression1137    expect(result.success).to.be.true;1138    // tslint:disable-next-line: no-unused-expression1139    expect(whiteListedBefore).to.be.false;1140    // tslint:disable-next-line: no-unused-expression1141    expect(whiteListedAfter).to.be.true;1142  });1143}11441145export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1146  await usingApi(async (api) => {11471148    const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();11491150    // Run the transaction1151    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1152    const events = await submitTransactionAsync(sender, tx);1153    const result = getGenericResult(events);11541155    const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();11561157    // What to expect1158    // tslint:disable-next-line:no-unused-expression1159    expect(result.success).to.be.true;1160    // tslint:disable-next-line: no-unused-expression1161    expect(whiteListedBefore).to.be.true;1162    // tslint:disable-next-line: no-unused-expression1163    expect(whiteListedAfter).to.be.true;1164  });1165}11661167export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1168  await usingApi(async (api) => {1169    1170    // Run the transaction1171    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1172    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1173    const result = getGenericResult(events);11741175    // What to expect1176    // tslint:disable-next-line:no-unused-expression1177    expect(result.success).to.be.false;1178  });1179}11801181export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1182  await usingApi(async (api) => {1183    // Run the transaction1184    const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1185    const events = await submitTransactionAsync(sender, tx);1186    const result = getGenericResult(events);11871188    // What to expect1189    // tslint:disable-next-line:no-unused-expression1190    expect(result.success).to.be.true;1191  });1192}11931194export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1195  await usingApi(async (api) => {1196    // Run the transaction1197    const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1198    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1199    const result = getGenericResult(events);12001201    // What to expect1202    // tslint:disable-next-line:no-unused-expression1203    expect(result.success).to.be.false;1204  });1205}12061207export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1208  : Promise<ICollectionInterface | null> => {1209  return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;1210};12111212export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1213  // set global object - collectionsCount1214  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();1215};12161217export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {1218  return await usingApi(async (api) => {1219    return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;1220  });1221}12221223export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1224  return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().Owner);1225}12261227export async function waitNewBlocks(blocksCount = 1): Promise<void> {1228  await usingApi(async (api) => {1229    const promise = new Promise<void>(async (resolve) => {1230      const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1231        if (blocksCount > 0) {1232          blocksCount--;1233        } else {1234          unsubscribe();1235          resolve();1236        }1237      });1238    });1239    return promise;1240  });1241}
after · 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 type { AccountId, EventRecord } from '@polkadot/types/interfaces';8import { IKeyringPair } from '@polkadot/types/types';9import { evmToAddress } from '@polkadot/util-crypto';10import { BigNumber } from 'bignumber.js';11import BN from 'bn.js';12import chai from 'chai';13import chaiAsPromised from 'chai-as-promised';14import { alicesPublicKey } from '../accounts';15import privateKey from '../substrate/privateKey';16import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';17import { ICollectionInterface } from '../types';18import { hexToStr, strToUTF16, utf16ToStr } from './util';1920chai.use(chaiAsPromised);21const expect = chai.expect;2223export type CrossAccountId = {24  substrate: string,25} | {26  ethereum: string,27};28export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {29  if (typeof input === 'string')30    return { substrate: input };31  if ('address' in input) {32    return { substrate: input.address };33  }34  if ('ethereum' in input) {35    input.ethereum = input.ethereum.toLowerCase();36    return input;37  }38  if ('substrate' in input) {39    return input;40  }4142  // AccountId43  return {substrate: input.toString()};44}45export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {46  input = normalizeAccountId(input);47  if ('substrate' in input) {48    return input.substrate;49  } else {50    return evmToAddress(input.ethereum);51  }52}5354export const U128_MAX = (1n << 128n) - 1n;5556const MICROUNIQUE = 1_000_000_000n;57const MILLIUNIQUE = 1_000n * MICROUNIQUE;58const CENTIUNIQUE = 10n * MILLIUNIQUE;59export const UNIQUE = 100n * CENTIUNIQUE;6061type GenericResult = {62  success: boolean,63};6465interface CreateCollectionResult {66  success: boolean;67  collectionId: number;68}6970interface CreateItemResult {71  success: boolean;72  collectionId: number;73  itemId: number;74  recipient?: CrossAccountId;75}7677interface TransferResult {78  success: boolean;79  collectionId: number;80  itemId: number;81  sender?: CrossAccountId;82  recipient?: CrossAccountId;83  value: bigint;84}8586interface IReFungibleOwner {87  fraction: BN;88  owner: number[];89}9091interface ITokenDataType {92  owner: IKeyringPair;93  constData: number[];94  variableData: number[];95}9697interface IGetMessage {98  checkMsgNftMethod: string;99  checkMsgTrsMethod: string;100  checkMsgSysMethod: string;101}102103export interface IFungibleTokenDataType {104  value: number;105}106107export interface IChainLimits {108  collectionNumbersLimit: number;109	accountTokenOwnershipLimit: number;110	collectionsAdminsLimit: number;111	customDataLimit: number;112	nftSponsorTransferTimeout: number;113	fungibleSponsorTransferTimeout: number;114	refungibleSponsorTransferTimeout: number;115	offchainSchemaLimit: number;116	variableOnChainSchemaLimit: number;117	constOnChainSchemaLimit: number;118}119120export interface IReFungibleTokenDataType {121  owner: IReFungibleOwner[];122  constData: number[];123  variableData: number[];124}125126export function nftEventMessage(events: EventRecord[]): IGetMessage {127  let checkMsgNftMethod = '';128  let checkMsgTrsMethod = '';129  let checkMsgSysMethod = '';130  events.forEach(({ event: { method, section } }) => {131    if (section === 'nft') {132      checkMsgNftMethod = method;133    } else if (section === 'treasury') {134      checkMsgTrsMethod = method;135    } else if (section === 'system') {136      checkMsgSysMethod = method;137    } else { return null; }138  });139  const result: IGetMessage = {140    checkMsgNftMethod,141    checkMsgTrsMethod,142    checkMsgSysMethod,143  };144  return result;145}146147export function getGenericResult(events: EventRecord[]): GenericResult {148  const result: GenericResult = {149    success: false,150  };151  events.forEach(({ event: { method } }) => {152    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);153    if (method === 'ExtrinsicSuccess') {154      result.success = true;155    }156  });157  return result;158}159160161162export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {163  let success = false;164  let collectionId = 0;165  events.forEach(({ event: { data, method, section } }) => {166    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);167    if (method == 'ExtrinsicSuccess') {168      success = true;169    } else if ((section == 'nft') && (method == 'CollectionCreated')) {170      collectionId = parseInt(data[0].toString());171    }172  });173  const result: CreateCollectionResult = {174    success,175    collectionId,176  };177  return result;178}179180export function getCreateItemResult(events: EventRecord[]): CreateItemResult {181  let success = false;182  let collectionId = 0;183  let itemId = 0;184  let recipient;185  events.forEach(({ event: { data, method, section } }) => {186    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);187    if (method == 'ExtrinsicSuccess') {188      success = true;189    } else if ((section == 'nft') && (method == 'ItemCreated')) {190      collectionId = parseInt(data[0].toString());191      itemId = parseInt(data[1].toString());192      recipient = data[2].toJSON();193    }194  });195  const result: CreateItemResult = {196    success,197    collectionId,198    itemId,199    recipient,200  };201  return result;202}203204export function getTransferResult(events: EventRecord[]): TransferResult {205  const result: TransferResult = {206    success: false,207    collectionId: 0,208    itemId: 0,209    value: 0n,210  };211212  events.forEach(({ event: { data, method, section } }) => {213    if (method === 'ExtrinsicSuccess') {214      result.success = true;215    } else if (section === 'nft' && method === 'Transfer') {216      result.collectionId = +data[0].toString();217      result.itemId = +data[1].toString();218      result.sender = data[2].toJSON() as CrossAccountId;219      result.recipient = data[3].toJSON() as CrossAccountId;220      result.value = BigInt(data[4].toString());221    }222  });223224  return result;225}226227interface Nft {228  type: 'NFT';229}230231interface Fungible {232  type: 'Fungible';233  decimalPoints: number;234}235236interface ReFungible {237  type: 'ReFungible';238}239240type CollectionMode = Nft | Fungible | ReFungible;241242export type CreateCollectionParams = {243  mode: CollectionMode,244  name: string,245  description: string,246  tokenPrefix: string,247};248249const defaultCreateCollectionParams: CreateCollectionParams = {250  description: 'description',251  mode: { type: 'NFT' },252  name: 'name',253  tokenPrefix: 'prefix',254};255256export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {257  const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };258259  let collectionId = 0;260  await usingApi(async (api) => {261    // Get number of collections before the transaction262    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);263264    // Run the CreateCollection transaction265    const alicePrivateKey = privateKey('//Alice');266267    let modeprm = {};268    if (mode.type === 'NFT') {269      modeprm = { nft: null };270    } else if (mode.type === 'Fungible') {271      modeprm = { fungible: mode.decimalPoints };272    } else if (mode.type === 'ReFungible') {273      modeprm = { refungible: null };274    }275276    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);277    const events = await submitTransactionAsync(alicePrivateKey, tx);278    const result = getCreateCollectionResult(events);279280    // Get number of collections after the transaction281    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);282283    // Get the collection284    const collection: any = (await api.query.nft.collectionById(result.collectionId) as any).toJSON();285286    // What to expect287    // tslint:disable-next-line:no-unused-expression288    expect(result.success).to.be.true;289    expect(result.collectionId).to.be.equal(BcollectionCount);290    // tslint:disable-next-line:no-unused-expression291    expect(collection).to.be.not.null;292    expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');293    expect(collection.owner).to.be.equal(toSubstrateAddress(alicesPublicKey));294    expect(utf16ToStr(collection.name)).to.be.equal(name);295    expect(utf16ToStr(collection.description)).to.be.equal(description);296    expect(hexToStr(collection.tokenPrefix)).to.be.equal(tokenPrefix);297298    collectionId = result.collectionId;299  });300301  return collectionId;302}303304export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {305  const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };306307  let modeprm = {};308  if (mode.type === 'NFT') {309    modeprm = { nft: null };310  } else if (mode.type === 'Fungible') {311    modeprm = { fungible: mode.decimalPoints };312  } else if (mode.type === 'ReFungible') {313    modeprm = { refungible: null };314  }315316  await usingApi(async (api) => {317    // Get number of collections before the transaction318    const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());319320    // Run the CreateCollection transaction321    const alicePrivateKey = privateKey('//Alice');322    const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);323    const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;324    const result = getCreateCollectionResult(events);325326    // Get number of collections after the transaction327    const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());328329    // What to expect330    // tslint:disable-next-line:no-unused-expression331    expect(result.success).to.be.false;332    expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');333  });334}335336export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {337  let bal = new BigNumber(0);338  let unused;339  do {340    const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;341    const keyring = new Keyring({ type: 'sr25519' });342    unused = keyring.addFromUri(`//${randomSeed}`);343    bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());344  } while (bal.toFixed() != '0');345  return unused;346}347348export async function getAllowance(collectionId: number, tokenId: number, owner: string, approved: string) {349  return await usingApi(async (api) => {350    const bn = await api.query.nft.allowances(collectionId, [tokenId, owner, approved]) as unknown as BN;351    return BigInt(bn.toString());352  });353}354355export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {356  return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));357}358359export async function findNotExistingCollection(api: ApiPromise): Promise<number> {360  const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;361  const newCollection: number = totalNumber + 1;362  return newCollection;363}364365function getDestroyResult(events: EventRecord[]): boolean {366  let success = false;367  events.forEach(({ event: { method } }) => {368    if (method == 'ExtrinsicSuccess') {369      success = true;370    }371  });372  return success;373}374375export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {376  await usingApi(async (api) => {377    // Run the DestroyCollection transaction378    const alicePrivateKey = privateKey(senderSeed);379    const tx = api.tx.nft.destroyCollection(collectionId);380    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;381  });382}383384export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {385  await usingApi(async (api) => {386    // Run the DestroyCollection transaction387    const alicePrivateKey = privateKey(senderSeed);388    const tx = api.tx.nft.destroyCollection(collectionId);389    const events = await submitTransactionAsync(alicePrivateKey, tx);390    const result = getDestroyResult(events);391392    // Get the collection393    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();394395    // What to expect396    expect(result).to.be.true;397    expect(collection).to.be.null;398  });399}400401export async function queryCollectionLimits(collectionId: number) {402  return await usingApi(async (api) => {403    return ((await api.query.nft.collectionById(collectionId)).toJSON() as any).limits;404  });405}406407export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {408  await usingApi(async (api) => {409    const oldLimits = await queryCollectionLimits(collectionId);410    const newLimits = { ...oldLimits as any, ...limits };411    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);412    const events = await submitTransactionAsync(sender, tx);413    const result = getGenericResult(events);414415    expect(result.success).to.be.true;416  });417}418419export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {420  await usingApi(async (api) => {421    const oldLimits = await queryCollectionLimits(collectionId);422    const newLimits = { ...oldLimits as any, ...limits };423    const tx = api.tx.nft.setCollectionLimits(collectionId, newLimits);424    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;425    const result = getGenericResult(events);426427    expect(result.success).to.be.false;428  });429}430431export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {432  await usingApi(async (api) => {433434    // Run the transaction435    const senderPrivateKey = privateKey(sender);436    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);437    const events = await submitTransactionAsync(senderPrivateKey, tx);438    const result = getGenericResult(events);439440    // Get the collection441    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();442443    // What to expect444    expect(result.success).to.be.true;445    expect(collection.sponsorship).to.deep.equal({446      unconfirmed: sponsor,447    });448  });449}450451export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {452  await usingApi(async (api) => {453454    // Run the transaction455    const alicePrivateKey = privateKey(sender);456    const tx = api.tx.nft.removeCollectionSponsor(collectionId);457    const events = await submitTransactionAsync(alicePrivateKey, tx);458    const result = getGenericResult(events);459460    // Get the collection461    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();462463    // What to expect464    expect(result.success).to.be.true;465    expect(collection.sponsorship).to.be.deep.equal({ disabled: null });466  });467}468469export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {470  await usingApi(async (api) => {471472    // Run the transaction473    const alicePrivateKey = privateKey(senderSeed);474    const tx = api.tx.nft.removeCollectionSponsor(collectionId);475    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;476  });477}478479export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {480  await usingApi(async (api) => {481482    // Run the transaction483    const alicePrivateKey = privateKey(senderSeed);484    const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);485    await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;486  });487}488489export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {490  await usingApi(async (api) => {491492    // Run the transaction493    const sender = privateKey(senderSeed);494    const tx = api.tx.nft.confirmSponsorship(collectionId);495    const events = await submitTransactionAsync(sender, tx);496    const result = getGenericResult(events);497498    // Get the collection499    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();500501    // What to expect502    expect(result.success).to.be.true;503    expect(collection.sponsorship).to.be.deep.equal({504      confirmed: sender.address,505    });506  });507}508509510export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {511  await usingApi(async (api) => {512513    // Run the transaction514    const sender = privateKey(senderSeed);515    const tx = api.tx.nft.confirmSponsorship(collectionId);516    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;517  });518}519520export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {521522  await usingApi(async (api) => {523    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);524    const events = await submitTransactionAsync(sender, tx);525    const result = getGenericResult(events);526527    expect(result.success).to.be.true;528  });529}530531export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {532533  await usingApi(async (api) => {534    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);535    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;536    const result = getGenericResult(events);537538    expect(result.success).to.be.false;539  });540}541542export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {543  await usingApi(async (api) => {544    const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);545    const events = await submitTransactionAsync(sender, tx);546    const result = getGenericResult(events);547548    expect(result.success).to.be.true;549  });550}551552export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {553  await usingApi(async (api) => {554    const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);555    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;556    const result = getGenericResult(events);557558    expect(result.success).to.be.false;559  });560}561562export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {563564  await usingApi(async (api) => {565566    const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);567    const events = await submitTransactionAsync(sender, tx);568    const result = getGenericResult(events);569570    expect(result.success).to.be.true;571  });572}573574export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {575576  await usingApi(async (api) => {577578    const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);579    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;580    const result = getGenericResult(events);581582    expect(result.success).to.be.false;583  });584}585586export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {587  await usingApi(async (api) => {588    const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);589    const events = await submitTransactionAsync(sender, tx);590    const result = getGenericResult(events);591592    expect(result.success).to.be.true;593  });594}595596export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {597  await usingApi(async (api) => {598    const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);599    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;600    const result = getGenericResult(events);601602    expect(result.success).to.be.false;603  });604}605606export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {607  await usingApi(async (api) => {608    const tx = api.tx.nft.toggleContractWhiteList(contractAddress, value);609    const events = await submitTransactionAsync(sender, tx);610    const result = getGenericResult(events);611612    expect(result.success).to.be.true;613  });614}615616export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) {617  let whitelisted = false;618  await usingApi(async (api) => {619    whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean;620  });621  return whitelisted;622}623624export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {625  await usingApi(async (api) => {626    const tx = api.tx.nft.addToContractWhiteList(contractAddress.toString(), user.toString());627    const events = await submitTransactionAsync(sender, tx);628    const result = getGenericResult(events);629630    expect(result.success).to.be.true;631  });632}633634export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {635  await usingApi(async (api) => {636    const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());637    const events = await submitTransactionAsync(sender, tx);638    const result = getGenericResult(events);639640    expect(result.success).to.be.true;641  });642}643644export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {645  await usingApi(async (api) => {646    const tx = api.tx.nft.removeFromContractWhiteList(contractAddress.toString(), user.toString());647    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;648    const result = getGenericResult(events);649650    expect(result.success).to.be.false;651  });652}653654export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {655  await usingApi(async (api) => {656    const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));657    const events = await submitTransactionAsync(sender, tx);658    const result = getGenericResult(events);659660    expect(result.success).to.be.true;661  });662}663664export async function setVariableMetaDataExpectFailure(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {665  await usingApi(async (api) => {666    const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex'));667    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;668  });669}670671export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {672  await usingApi(async (api) => {673    const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));674    const events = await submitTransactionAsync(sender, tx);675    const result = getGenericResult(events);676677    expect(result.success).to.be.true;678  });679}680681export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {682  await usingApi(async (api) => {683    const tx = api.tx.nft.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));684    await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;685  });686}687688export interface CreateFungibleData {689  readonly Value: bigint;690}691692export interface CreateReFungibleData { }693export interface CreateNftData { }694695export type CreateItemData = {696  NFT: CreateNftData;697} | {698  Fungible: CreateFungibleData;699} | {700  ReFungible: CreateReFungibleData;701};702703export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {704  await usingApi(async (api) => {705    const tx = api.tx.nft.burnItem(collectionId, tokenId, value);706    const events = await submitTransactionAsync(owner, tx);707    const result = getGenericResult(events);708    // Get the item709    const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();710    // What to expect711    // tslint:disable-next-line:no-unused-expression712    expect(result.success).to.be.true;713    // tslint:disable-next-line:no-unused-expression714    expect(item).to.be.null;715  });716}717718export async function719approveExpectSuccess(720  collectionId: number,721  tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1,722) {723  await usingApi(async (api: ApiPromise) => {724    approved = normalizeAccountId(approved);725    const allowanceBefore =726      await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;727    const approveNftTx = api.tx.nft.approve(approved, collectionId, tokenId, amount);728    const events = await submitTransactionAsync(owner, approveNftTx);729    const result = getCreateItemResult(events);730    // tslint:disable-next-line:no-unused-expression731    expect(result.success).to.be.true;732    const allowanceAfter =733      await api.query.nft.allowances(collectionId, [tokenId, owner.address, toSubstrateAddress(approved)]) as unknown as BN;734    expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());735  });736}737738export async function739transferFromExpectSuccess(740  collectionId: number,741  tokenId: number,742  accountApproved: IKeyringPair,743  accountFrom: IKeyringPair | CrossAccountId,744  accountTo: IKeyringPair | CrossAccountId,745  value: number | bigint = 1,746  type = 'NFT',747) {748  await usingApi(async (api: ApiPromise) => {749    const to = normalizeAccountId(accountTo);750    let balanceBefore = new BN(0);751    if (type === 'Fungible') {752      balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;753    }754    const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);755    const events = await submitTransactionAsync(accountApproved, transferFromTx);756    const result = getCreateItemResult(events);757    // tslint:disable-next-line:no-unused-expression758    expect(result.success).to.be.true;759    if (type === 'NFT') {760      const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON() as ITokenDataType;761      expect(nftItemData.owner).to.be.deep.equal(to);762    }763    if (type === 'Fungible') {764      const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;765      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());766    }767    if (type === 'ReFungible') {768      const nftItemData =769        (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).toJSON() as IReFungibleTokenDataType;770      expect(nftItemData.owner[0].owner).to.be.deep.equal(normalizeAccountId(to));771      expect(nftItemData.owner[0].fraction).to.be.equal(value);772    }773  });774}775776export async function777transferFromExpectFail(778  collectionId: number,779  tokenId: number,780  accountApproved: IKeyringPair,781  accountFrom: IKeyringPair,782  accountTo: IKeyringPair,783  value: number | bigint = 1,784) {785  await usingApi(async (api: ApiPromise) => {786    const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);787    const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;788    const result = getCreateCollectionResult(events);789    // tslint:disable-next-line:no-unused-expression790    expect(result.success).to.be.false;791  });792}793794/* eslint no-async-promise-executor: "off" */795async function getBlockNumber(api: ApiPromise): Promise<number> {796  return new Promise<number>(async (resolve) => {797    const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {798      unsubscribe();799      resolve(head.number.toNumber());800    });801  });802}803804export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {805  await usingApi(async (api) => {806    const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));807    const events = await submitTransactionAsync(sender, changeAdminTx);808    const result = getCreateCollectionResult(events);809    expect(result.success).to.be.true;810  });811}812813export async function814getFreeBalance(account: IKeyringPair) : Promise<BigNumber>815{816  let balance = new BigNumber(0) ;817  await usingApi(async (api) => {818    balance = new BigNumber((await api.query.system.account(account.address)).data.free.toString());819  });820821  return balance;822}823824export async function825scheduleTransferExpectSuccess(826  collectionId: number,827  tokenId: number,828  sender: IKeyringPair,829  recipient: IKeyringPair,830  value: number | bigint = 1,831  blockTimeMs: number,832  blockSchedule: number,833) {834  await usingApi(async (api: ApiPromise) => {835    const blockNumber: number | undefined = await getBlockNumber(api);836    const expectedBlockNumber = blockNumber + blockSchedule;837838    expect(blockNumber).to.be.greaterThan(0);839    const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);840    const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);841842    await submitTransactionAsync(sender, scheduleTx);843844    const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());845846    const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as any as ITokenDataType;847    expect(toSubstrateAddress(nftItemDataBefore.owner)).to.be.equal(sender.address);848849    // sleep for 4 blocks850    await new Promise(resolve => setTimeout(resolve, blockTimeMs * (blockSchedule + 1)));851852    const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());853854    const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;855    expect(toSubstrateAddress(nftItemData.owner)).to.be.equal(recipient.address);856    expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());857  });858}859860861export async function862transferExpectSuccess(863  collectionId: number,864  tokenId: number,865  sender: IKeyringPair,866  recipient: IKeyringPair | CrossAccountId,867  value: number | bigint = 1,868  type = 'NFT',869) {870  await usingApi(async (api: ApiPromise) => {871    const to = normalizeAccountId(recipient);872873    let balanceBefore = new BN(0);874    if (type === 'Fungible') {875      balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;876    }877    const transferTx = api.tx.nft.transfer(to, collectionId, tokenId, value);878    const events = await submitTransactionAsync(sender, transferTx);879    const result = getTransferResult(events);880    // tslint:disable-next-line:no-unused-expression881    expect(result.success).to.be.true;882    expect(result.collectionId).to.be.equal(collectionId);883    expect(result.itemId).to.be.equal(tokenId);884    expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));885    expect(result.recipient).to.be.deep.equal(to);886    expect(result.value.toString()).to.be.equal(value.toString());887    if (type === 'NFT') {888      const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;889      expect(nftItemData.owner).to.be.deep.equal(to);890    }891    if (type === 'Fungible') {892      const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to)) as any).value as unknown as BN;893      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());894    }895    if (type === 'ReFungible') {896      const nftItemData =897        (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;898      const expectedOwner = toSubstrateAddress(to);899      const ownerIndex = nftItemData.owner.findIndex(v => toSubstrateAddress(v.owner as any as string) == expectedOwner);900      expect(ownerIndex).to.not.equal(-1);901      expect(nftItemData.owner[ownerIndex].owner).to.be.deep.equal(normalizeAccountId(to));902      expect(nftItemData.owner[ownerIndex].fraction).to.be.greaterThanOrEqual(value as number);903    }904  });905}906907export async function908transferExpectFailure(909  collectionId: number,910  tokenId: number,911  sender: IKeyringPair,912  recipient: IKeyringPair,913  value: number | bigint = 1,914) {915  await usingApi(async (api: ApiPromise) => {916    const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);917    const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;918    if (events && Array.isArray(events)) {919      const result = getCreateCollectionResult(events);920      // tslint:disable-next-line:no-unused-expression921      expect(result.success).to.be.false;922    }923  });924}925926export async function927approveExpectFail(928  collectionId: number,929  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,930) {931  await usingApi(async (api: ApiPromise) => {932    const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);933    const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;934    const result = getCreateCollectionResult(events);935    // tslint:disable-next-line:no-unused-expression936    expect(result.success).to.be.false;937  });938}939940export async function getFungibleBalance(941  collectionId: number,942  owner: string,943) {944  return await usingApi(async (api) => {945    const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as { value: string };946    return BigInt(response.value);947  });948}949950export async function createFungibleItemExpectSuccess(951  sender: IKeyringPair,952  collectionId: number,953  data: CreateFungibleData,954  owner: CrossAccountId | string = sender.address,955) {956  return await usingApi(async (api) => {957    const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), { Fungible: data });958959    const events = await submitTransactionAsync(sender, tx);960    const result = getCreateItemResult(events);961962    expect(result.success).to.be.true;963    return result.itemId;964  });965}966967export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {968  let newItemId = 0;969  await usingApi(async (api) => {970    const to = normalizeAccountId(owner);971    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);972    const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();973    const AItemBalance = new BigNumber(Aitem.value);974975    let tx;976    if (createMode === 'Fungible') {977      const createData = { fungible: { value: 10 } };978      tx = api.tx.nft.createItem(collectionId, to, createData);979    } else if (createMode === 'ReFungible') {980      const createData = { refungible: { const_data: [], variable_data: [], pieces: 100 } };981      tx = api.tx.nft.createItem(collectionId, to, createData);982    } else {983      const createData = { nft: { const_data: [], variable_data: [] } };984      tx = api.tx.nft.createItem(collectionId, to, createData);985    }986987    const events = await submitTransactionAsync(sender, tx);988    const result = getCreateItemResult(events);989990    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);991    const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, toSubstrateAddress(to))).toJSON();992    const BItemBalance = new BigNumber(Bitem.value);993994    // What to expect995    // tslint:disable-next-line:no-unused-expression996    expect(result.success).to.be.true;997    if (createMode === 'Fungible') {998      expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);999    } else {1000      expect(BItemCount).to.be.equal(AItemCount + 1);1001    }1002    expect(collectionId).to.be.equal(result.collectionId);1003    expect(BItemCount.toString()).to.be.equal(result.itemId.toString());1004    expect(to).to.be.deep.equal(result.recipient);1005    newItemId = result.itemId;1006  });1007  return newItemId;1008}10091010export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {1011  await usingApi(async (api) => {1012    const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);10131014    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1015    const result = getCreateItemResult(events);10161017    expect(result.success).to.be.false;1018  });1019}10201021export async function setPublicAccessModeExpectSuccess(1022  sender: IKeyringPair, collectionId: number,1023  accessMode: 'Normal' | 'WhiteList',1024) {1025  await usingApi(async (api) => {10261027    // Run the transaction1028    const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1029    const events = await submitTransactionAsync(sender, tx);1030    const result = getGenericResult(events);10311032    // Get the collection1033    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();10341035    // What to expect1036    // tslint:disable-next-line:no-unused-expression1037    expect(result.success).to.be.true;1038    expect(collection.access).to.be.equal(accessMode);1039  });1040}10411042export async function setPublicAccessModeExpectFail(1043  sender: IKeyringPair, collectionId: number,1044  accessMode: 'Normal' | 'WhiteList',1045) {1046  await usingApi(async (api) => {10471048    // Run the transaction1049    const tx = api.tx.nft.setPublicAccessMode(collectionId, accessMode);1050    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1051    const result = getGenericResult(events);10521053    // What to expect1054    // tslint:disable-next-line:no-unused-expression1055    expect(result.success).to.be.false;1056  });1057}10581059export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1060  await setPublicAccessModeExpectSuccess(sender, collectionId, 'WhiteList');1061}10621063export async function enableWhiteListExpectFail(sender: IKeyringPair, collectionId: number) {1064  await setPublicAccessModeExpectFail(sender, collectionId, 'WhiteList');1065}10661067export async function disableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {1068  await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1069}10701071export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1072  await usingApi(async (api) => {10731074    // Run the transaction1075    const tx = api.tx.nft.setMintPermission(collectionId, enabled);1076    const events = await submitTransactionAsync(sender, tx);1077    const result = getGenericResult(events);10781079    // Get the collection1080    const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();10811082    // What to expect1083    // tslint:disable-next-line:no-unused-expression1084    expect(result.success).to.be.true;1085    expect(collection.mintMode).to.be.equal(enabled);1086  });1087}10881089export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1090  await setMintPermissionExpectSuccess(sender, collectionId, true);1091}10921093export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1094  await usingApi(async (api) => {1095    // Run the transaction1096    const tx = api.tx.nft.setMintPermission(collectionId, enabled);1097    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1098    const result = getCreateCollectionResult(events);1099    // tslint:disable-next-line:no-unused-expression1100    expect(result.success).to.be.false;1101  });1102}11031104export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1105  await usingApi(async (api) => {1106    // Run the transaction1107    const tx = api.tx.nft.setChainLimits(limits);1108    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1109    const result = getCreateCollectionResult(events);1110    // tslint:disable-next-line:no-unused-expression1111    expect(result.success).to.be.false;1112  });1113}11141115export async function isWhitelisted(collectionId: number, address: string) {1116  let whitelisted = false;1117  await usingApi(async (api) => {1118    whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;1119  });1120  return whitelisted;1121}11221123export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1124  await usingApi(async (api) => {11251126    const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();11271128    // Run the transaction1129    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1130    const events = await submitTransactionAsync(sender, tx);1131    const result = getGenericResult(events);11321133    const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();11341135    // What to expect1136    // tslint:disable-next-line:no-unused-expression1137    expect(result.success).to.be.true;1138    // tslint:disable-next-line: no-unused-expression1139    expect(whiteListedBefore).to.be.false;1140    // tslint:disable-next-line: no-unused-expression1141    expect(whiteListedAfter).to.be.true;1142  });1143}11441145export async function addToWhiteListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1146  await usingApi(async (api) => {11471148    const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();11491150    // Run the transaction1151    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1152    const events = await submitTransactionAsync(sender, tx);1153    const result = getGenericResult(events);11541155    const whiteListedAfter = (await api.query.nft.whiteList(collectionId, address)).toJSON();11561157    // What to expect1158    // tslint:disable-next-line:no-unused-expression1159    expect(result.success).to.be.true;1160    // tslint:disable-next-line: no-unused-expression1161    expect(whiteListedBefore).to.be.true;1162    // tslint:disable-next-line: no-unused-expression1163    expect(whiteListedAfter).to.be.true;1164  });1165}11661167export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1168  await usingApi(async (api) => {11691170    // Run the transaction1171    const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));1172    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1173    const result = getGenericResult(events);11741175    // What to expect1176    // tslint:disable-next-line:no-unused-expression1177    expect(result.success).to.be.false;1178  });1179}11801181export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1182  await usingApi(async (api) => {1183    // Run the transaction1184    const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1185    const events = await submitTransactionAsync(sender, tx);1186    const result = getGenericResult(events);11871188    // What to expect1189    // tslint:disable-next-line:no-unused-expression1190    expect(result.success).to.be.true;1191  });1192}11931194export async function removeFromWhiteListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1195  await usingApi(async (api) => {1196    // Run the transaction1197    const tx = api.tx.nft.removeFromWhiteList(collectionId, normalizeAccountId(address));1198    const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1199    const result = getGenericResult(events);12001201    // What to expect1202    // tslint:disable-next-line:no-unused-expression1203    expect(result.success).to.be.false;1204  });1205}12061207export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1208  : Promise<ICollectionInterface | null> => {1209  return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;1210};12111212export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1213  // set global object - collectionsCount1214  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();1215};12161217export async function queryCollectionExpectSuccess(collectionId: number): Promise<ICollectionInterface> {1218  return await usingApi(async (api) => {1219    return (await api.query.nft.collectionById(collectionId)).toJSON() as unknown as ICollectionInterface;1220  });1221}12221223export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1224  return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().owner);1225}12261227export async function waitNewBlocks(blocksCount = 1): Promise<void> {1228  await usingApi(async (api) => {1229    const promise = new Promise<void>(async (resolve) => {1230      const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1231        if (blocksCount > 0) {1232          blocksCount--;1233        } else {1234          unsubscribe();1235          resolve();1236        }1237      });1238    });1239    return promise;1240  });1241}