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

difftreelog

createMultipleItems test

kpozdnikin2021-01-13parent: #2c99b94.patch.diff
in: master

3 files changed

modifiedtests/package-lock.jsondiffbeforeafterboth
--- a/tests/package-lock.json
+++ b/tests/package-lock.json
@@ -4824,6 +4824,11 @@
       "integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==",
       "dev": true
     },
+    "@types/sprintf-js": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmjs.org/@types/sprintf-js/-/sprintf-js-1.1.2.tgz",
+      "integrity": "sha512-hkgzYF+qnIl8uTO8rmUSVSfQ8BIfMXC4yJAF4n8BE758YsKBZvFC4NumnAegj7KmylP0liEZNpb9RRGFMbFejA=="
+    },
     "@types/stack-utils": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz",
@@ -5867,6 +5872,14 @@
       "dev": true,
       "requires": {
         "sprintf-js": "~1.0.2"
+      },
+      "dependencies": {
+        "sprintf-js": {
+          "version": "1.0.3",
+          "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
+          "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
+          "dev": true
+        }
       }
     },
     "arr-diff": {
@@ -20684,10 +20697,9 @@
       }
     },
     "sprintf-js": {
-      "version": "1.0.3",
-      "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
-      "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
-      "dev": true
+      "version": "1.1.2",
+      "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
+      "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug=="
     },
     "sshpk": {
       "version": "1.16.1",
modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -21,7 +21,8 @@
     "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
     "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
-    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts"
+    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts"
   },
   "author": "",
   "license": "Apache 2.0",
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
before · tests/src/createMultipleItems.test.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//5import { ApiPromise } from '@polkadot/api';6import { assert } from 'chai';7import { alicesPublicKey } from './accounts';8import privateKey from './substrate/privateKey';9import usingApi from './substrate/substrate-api';10import waitNewBlocks from './substrate/wait-new-blocks';1112const idCollection = 12;1314describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {15  it('Create  0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {16    await usingApi(async (api: ApiPromise) => {1718    });19  });20});2122describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {23  it('Create token with not existing type', async () => {24    await usingApi(async (api: ApiPromise) => {2526    });27  });2829  it('Create token in not existing collection', async () => {30    await usingApi(async (api: ApiPromise) => {3132    });33  });3435  it('Create token that has reached the maximum data limit', async () => {36    await usingApi(async (api: ApiPromise) => {3738    });39  });4041  it('Create tokens with different types', async () => {42    await usingApi(async (api: ApiPromise) => {4344    });45  });4647  it('Create tokens in not existing collection', async () => {48    await usingApi(async (api: ApiPromise) => {4950    });51  });5253  it('Create tokens with different data limits <> maximum data limit', async () => {54    await usingApi(async (api: ApiPromise) => {5556    });57  });58});5960describe.skip('integration test: ext. createMultipleItems():', () => {61  it('Create two NFT tokens in active NFT collection', async () => {62    await usingApi(async (api) => {63      const AitemListIndex = await api.query.nft.itemListIndex(idCollection);64      console.log(`itemListIndex count (before): ${AitemListIndex}`);65      const args = ['NFT', 'NFT'];66      const alicePrivateKey = privateKey('//Alice');67      const createMultipleItems = await api.tx.nft68      .createMultipleItems(idCollection, alicesPublicKey, args)69      .signAndSend(alicePrivateKey);70      // tslint:disable-next-line: no-unused-expression71      assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');72      console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);73      await waitNewBlocks(api);74      const BitemListIndex = await api.query.nft.itemListIndex(idCollection);75      console.log(`itemListIndex count (after): ${BitemListIndex}`);76      if (BitemListIndex === AitemListIndex) { assert.fail('Corret token not added in collection!'); }77    });78  });79  it('(!negative test!) Create two Fungible tokens in active NFT collection', async () => {80    await usingApi(async (api) => {81      const AitemListIndex = await api.query.nft.itemListIndex(idCollection);82      console.log(`itemListIndex count (before): ${AitemListIndex}`);83      const args = ['Fungible', 'Fungible'];84      const alicePrivateKey = privateKey('//Alice');85      const createMultipleItems = await api.tx.nft86      .createMultipleItems(idCollection, alicesPublicKey, args)87      .signAndSend(alicePrivateKey);88      // tslint:disable-next-line: no-unused-expression89      assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');90      console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);91      await waitNewBlocks(api);92      const BitemListIndex = await api.query.nft.itemListIndex(idCollection);93      console.log(`itemListIndex count (after): ${BitemListIndex}`);94      if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }95    });96  });97  it('(!negative test!) Create two ReFungible tokens in active NFT collection', async () => {98    await usingApi(async (api) => {99      const AitemListIndex = await api.query.nft.itemListIndex(idCollection);100      console.log(`itemListIndex count (before): ${AitemListIndex}`);101      const args = ['ReFungible', 'ReFungible'];102      const alicePrivateKey = privateKey('//Alice');103      const createMultipleItems = await api.tx.nft104      .createMultipleItems(idCollection, alicesPublicKey, args)105      .signAndSend(alicePrivateKey);106      // tslint:disable-next-line: no-unused-expression107      assert.exists(createMultipleItems, 'createMultipleItems is neither `null` or `undefined`');108      console.log(`Ext. createMultipleItems submitted with hash: ${createMultipleItems}`);109      await waitNewBlocks(api);110      const BitemListIndex = await api.query.nft.itemListIndex(idCollection);111      console.log(`itemListIndex count (after): ${BitemListIndex}`);112      if (BitemListIndex > AitemListIndex) { assert.fail('Incorrect token added in collection!'); }113    });114  });115});
after · tests/src/createMultipleItems.test.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//5import { ApiPromise } from '@polkadot/api';6import BN from 'bn.js';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516interface ITokenDataType {17  Owner: number[];18  ConstData: number[];19  VariableData: number[];20}2122describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {23  it('Create  0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {24    await usingApi(async (api: ApiPromise) => {25      const collectionId = await createCollectionExpectSuccess();26      const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;27      expect(itemsListIndexBefore.toNumber()).to.be.equal(0);28      const Alice = privateKey('//Alice');29      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];30      const createMultipleItemsTx = await api.tx.nft31        .createMultipleItems(collectionId, Alice.address, args);32      await submitTransactionAsync(Alice, createMultipleItemsTx);33      const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;34      expect(itemsListIndexAfter.toNumber()).to.be.equal(3);35      const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;36      const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;37      const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;3839      expect(token1Data.Owner.toString()).to.be.equal(Alice.address);40      expect(token2Data.Owner.toString()).to.be.equal(Alice.address);41      expect(token3Data.Owner.toString()).to.be.equal(Alice.address);4243      expect(token1Data.ConstData.toString()).to.be.equal('0x31');44      expect(token2Data.ConstData.toString()).to.be.equal('0x32');45      expect(token3Data.ConstData.toString()).to.be.equal('0x33');4647      expect(token1Data.VariableData.toString()).to.be.equal('0x31');48      expect(token2Data.VariableData.toString()).to.be.equal('0x32');49      expect(token3Data.VariableData.toString()).to.be.equal('0x33');5051      // garbage collection :-D52      await destroyCollectionExpectSuccess(collectionId);53    });54  });55});5657describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {58  it('Create token with not existing type', async () => {59    await usingApi(async (api: ApiPromise) => {60      const collectionId = await createCollectionExpectSuccess();61      const Alice = privateKey('//Alice');62      try {63        const createMultipleItemsTx = await api.tx.nft64          .createMultipleItems(collectionId, Alice.address, ['UNKNOWN', 'UNKNOWN', 'UNKNOWN']);65        await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;66      } catch (e) {67        // tslint:disable-next-line:no-unused-expression68        expect(e).to.be.exist;69      }70      // garbage collection :-D71      await destroyCollectionExpectSuccess(collectionId);72    });73  });7475  it('Create token in not existing collection', async () => {76    await usingApi(async (api: ApiPromise) => {77      const collectionId = await createCollectionExpectSuccess();78      const Alice = privateKey('//Alice');79      const createMultipleItemsTx = await api.tx.nft80        .createMultipleItems(collectionId + 1, Alice.address, ['NFT', 'NFT', 'NFT']);81      await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;82      // garbage collection :-D83      await destroyCollectionExpectSuccess(collectionId);84    });85  });8687  it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {88    await usingApi(async (api: ApiPromise) => {89      // NFT90      const collectionId = await createCollectionExpectSuccess();91      const Alice = privateKey('//Alice');92      const args = [93        { nft: ['A'.repeat(2049), 'A'.repeat(2049)] },94        { nft: ['B'.repeat(2049), 'B'.repeat(2049)] },95        { nft: ['C'.repeat(2049), 'C'.repeat(2049)] },96      ];97      const createMultipleItemsTx = await api.tx.nft98        .createMultipleItems(collectionId, Alice.address, args);99      await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;100      // garbage collection :-D101      await destroyCollectionExpectSuccess(collectionId);102103      // Fungible104      const collectionIdFungible = await createCollectionExpectSuccess();105      const argsFungible = [106        { fungible: parseInt('1'.repeat(2049), 10) },107        { fungible: parseInt('2'.repeat(2049), 10) },108        { fungible: parseInt('3'.repeat(2049), 10) },109      ];110      const createMultipleItemsTxFungible = await api.tx.nft111        .createMultipleItems(collectionIdFungible, Alice.address, argsFungible);112      await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTxFungible)).to.be.rejected;113      // garbage collection :-D114      await destroyCollectionExpectSuccess(collectionId);115    });116  });117118  it('Create tokens with different types', async () => {119    await usingApi(async (api: ApiPromise) => {120      const collectionId = await createCollectionExpectSuccess();121      const Alice = privateKey('//Alice');122      const createMultipleItemsTx = await api.tx.nft123        .createMultipleItems(collectionId, Alice.address, ['NFT', 'Fungible', 'ReFungible']);124      await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;125      // garbage collection :-D126      await destroyCollectionExpectSuccess(collectionId);127    });128  });129130  it('Create tokens with different data limits <> maximum data limit', async () => {131    await usingApi(async (api: ApiPromise) => {132      const collectionId = await createCollectionExpectSuccess();133      const Alice = privateKey('//Alice');134      const args = [135        { nft: ['A', 'A'] },136        { nft: ['B', 'B'.repeat(2049)] },137        { nft: ['C'.repeat(2049), 'C'] },138      ];139      const createMultipleItemsTx = await api.tx.nft140        .createMultipleItems(collectionId, Alice.address, args);141      await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;142      // garbage collection :-D143      await destroyCollectionExpectSuccess(collectionId);144    });145  });146});