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

difftreelog

Merge pull request #97 from usetech-llc/feature/NFTPAR-281_overflow_tests

Greg Zaitsev2021-02-12parents: #800a78f #22e2b6e.patch.diff
in: master
Fungible overflow tests

8 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -40,7 +40,8 @@
     "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
     "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
     "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
-    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts"
+    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
+    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts"
   },
   "author": "",
   "license": "SEE LICENSE IN ../LICENSE",
modifiedtests/src/approve.test.tsdiffbeforeafterboth
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -12,8 +12,11 @@
   approveExpectFail,
   approveExpectSuccess,
   createCollectionExpectSuccess,
+  createFungibleItemExpectSuccess,
   createItemExpectSuccess,
   destroyCollectionExpectSuccess,
+  transferFromExpectSuccess,
+  U128_MAX,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
addedtests/src/overflow.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/overflow.test.ts
@@ -0,0 +1,67 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { IKeyringPair } from "@polkadot/types/types";
+import chai from 'chai';
+import chaiAsPromised from "chai-as-promised";
+import privateKey from "./substrate/privateKey";
+import usingApi from "./substrate/substrate-api";
+import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFail, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from "./util/helpers";
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test fungible overflows', () => {
+    let alice: IKeyringPair;
+    let bob: IKeyringPair;
+    let charlie: IKeyringPair;
+
+    before(async () => {
+        await usingApi(async () => {
+            alice = privateKey('//Alice');
+            bob = privateKey('//Bob');
+            charlie = privateKey('//Charlie');
+        });
+    });
+
+    it('fails when overflows on transfer', async () => {
+        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+
+        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
+        await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');
+
+        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });
+        await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');
+
+        expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);
+        expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);
+    });
+
+    it('fails on allowance overflow', async () => {
+        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+
+        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
+        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);
+        await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);
+    });
+
+    it('fails when overflows on transferFrom', async () => {
+        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });
+
+        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
+        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);
+        await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');
+
+        expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);
+        expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('0');
+
+        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });
+        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);
+        await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);
+
+        expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);
+        expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('1');
+    });
+});
modifiedtests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth
--- a/tests/src/removeFromContractWhiteList.test.ts
+++ b/tests/src/removeFromContractWhiteList.test.ts
@@ -1,3 +1,8 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
 import privateKey from "./substrate/privateKey";
 import usingApi from "./substrate/substrate-api";
 import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from "./util/contracthelpers";
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -18,9 +18,10 @@
   return { provider: wsProvider, types: rtt };
 }
 
-export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {
+export default async function usingApi<T = void>(action: (api: ApiPromise) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {
   settings = settings || defaultApiOptions();
   let api: ApiPromise = new ApiPromise(settings);
+  let result: T = null as unknown as T;
 
   // TODO: Remove, this is temporary: Filter unneeded API output 
   // (Jaco promised it will be removed in the next version)
@@ -32,15 +33,16 @@
 
   try {
     await promisifySubstrate(api, async () => {
-      if(api) {
+      if (api) {
         await api.isReadyOrError;
-        await action(api);
+        result = await action(api);
       }
     })();
   } finally {
     await api.disconnect();
     console.error = consoleErr;
   }
+  return result as T;
 }
 
 enum TransactionStatus {
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
before · tests/src/transferFrom.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 chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi } from './substrate/substrate-api';10import {11  approveExpectFail,12  approveExpectSuccess,13  createCollectionExpectSuccess,14  createItemExpectSuccess,15  destroyCollectionExpectSuccess,16  transferFromExpectFail,17  transferFromExpectSuccess,18  burnItemExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {25  it('Execute the extrinsic and check nftItemList - owner of token', async () => {26    await usingApi(async (api: ApiPromise) => {27      const Alice = privateKey('//Alice');28      const Bob = privateKey('//Bob');29      const Charlie = privateKey('//Charlie');30      // nft31      const nftCollectionId = await createCollectionExpectSuccess();32      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');33      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3435      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3637      // fungible38      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});39      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');40      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);41      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');42      // reFungible43      const reFungibleCollectionId = await44        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});45      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');46      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);47      await transferFromExpectSuccess(reFungibleCollectionId,48        newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');49    });50  });51});5253describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {54  it('transferFrom for a collection that does not exist', async () => {55    await usingApi(async (api: ApiPromise) => {56      const Alice = privateKey('//Alice');57      const Bob = privateKey('//Bob');58      const Charlie = privateKey('//Charlie');59      // nft60      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;61      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);6263      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);6465      // fungible66      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;67      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);6869      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);70      // reFungible71      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;72      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);7374      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);75    });76  });7778  /* it('transferFrom for a collection that was destroyed', async () => {79    await usingApi(async (api: ApiPromise) => {80      this test copies approve negative test81    });82  }); */8384  /* it('transferFrom a token that does not exist', async () => {85    await usingApi(async (api: ApiPromise) => {86      this test copies approve negative test87    });88  }); */8990  /* it('transferFrom a token that was deleted', async () => {91    await usingApi(async (api: ApiPromise) => {92      this test copies approve negative test93    });94  }); */9596  it('transferFrom for not approved address', async () => {97    await usingApi(async (api: ApiPromise) => {98      const Alice = privateKey('//Alice');99      const Bob = privateKey('//Bob');100      const Charlie = privateKey('//Charlie');101      // nft102      const nftCollectionId = await createCollectionExpectSuccess();103      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');104105      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);106107      // fungible108      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});109      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');110      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);111      // reFungible112      const reFungibleCollectionId = await113        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});114      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');115      await transferFromExpectFail(reFungibleCollectionId,116        newReFungibleTokenId, Bob, Alice, Charlie, 1);117    });118  });119120  it('transferFrom incorrect token count', async () => {121    await usingApi(async (api: ApiPromise) => {122      const Alice = privateKey('//Alice');123      const Bob = privateKey('//Bob');124      const Charlie = privateKey('//Charlie');125      // nft126      const nftCollectionId = await createCollectionExpectSuccess();127      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');128      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);129130      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);131132      // fungible133      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});134      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');135      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);136      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);137      // reFungible138      const reFungibleCollectionId = await139        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});140      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');141      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);142      await transferFromExpectFail(reFungibleCollectionId,143        newReFungibleTokenId, Bob, Alice, Charlie, 2);144    });145  });146147  it('execute transferFrom from account that is not owner of collection', async () => {148    await usingApi(async (api: ApiPromise) => {149      const Alice = privateKey('//Alice');150      const Bob = privateKey('//Bob');151      const Charlie = privateKey('//Charlie');152      const Dave = privateKey('//Dave');153      // nft154      const nftCollectionId = await createCollectionExpectSuccess();155      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');156      try {157        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);158        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);159      } catch (e) {160        // tslint:disable-next-line:no-unused-expression161        expect(e).to.be.exist;162      }163164      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);165166      // fungible167      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});168      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');169      try {170        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);171        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);172      } catch (e) {173        // tslint:disable-next-line:no-unused-expression174        expect(e).to.be.exist;175      }176      // reFungible177      const reFungibleCollectionId = await178        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');180      try {181        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);182        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);183      } catch (e) {184        // tslint:disable-next-line:no-unused-expression185        expect(e).to.be.exist;186      }187    });188  });189  it( 'transferFrom burnt token before approve NFT', async () => {190    await usingApi(async (api: ApiPromise) => {191      const Alice = privateKey('//Alice');192      const Bob = privateKey('//Bob');193      const Charlie = privateKey('//Charlie');194      // nft195      const nftCollectionId = await createCollectionExpectSuccess();196      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');197      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);198      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);199      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      200    });201  });202  it( 'transferFrom burnt token before approve Fungible', async () => {203    await usingApi(async (api: ApiPromise) => {204    const Alice = privateKey('//Alice');205      const Bob = privateKey('//Bob');206      const Charlie = privateKey('//Charlie');207      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});208      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');209      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);210      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);211      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);212          213    });214  }); 215  it( 'transferFrom burnt token before approve ReFungible', async () => {216    await usingApi(async (api: ApiPromise) => {217    const Alice = privateKey('//Alice');218      const Bob = privateKey('//Bob');219      const Charlie = privateKey('//Charlie');220      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});221      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');222      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);223      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);224      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);225          226    });227  });228  229  it( 'transferFrom burnt token after approve NFT', async () => {230    await usingApi(async (api: ApiPromise) => {231      const Alice = privateKey('//Alice');232      const Bob = privateKey('//Bob');233      const Charlie = privateKey('//Charlie');234      // nft235      const nftCollectionId = await createCollectionExpectSuccess();236      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');237      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);238      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);239      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      240    });241  });242  it( 'transferFrom burnt token after approve Fungible', async () => {243    await usingApi(async (api: ApiPromise) => {244    const Alice = privateKey('//Alice');245      const Bob = privateKey('//Bob');246      const Charlie = privateKey('//Charlie');247      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});248      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');249      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);250      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);251      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);252          253    });254  }); 255  it( 'transferFrom burnt token after approve ReFungible', async () => {256    await usingApi(async (api: ApiPromise) => {257    const Alice = privateKey('//Alice');258      const Bob = privateKey('//Bob');259      const Charlie = privateKey('//Charlie');260      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});261      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');262      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);263      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);264      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);265          266    });267  }); 268});
after · tests/src/transferFrom.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 chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi } from './substrate/substrate-api';10import {11  approveExpectFail,12  approveExpectSuccess,13  createCollectionExpectSuccess,14  createFungibleItemExpectSuccess,15  createItemExpectSuccess,16  destroyCollectionExpectSuccess,17  getAllowance,18  transferFromExpectFail,19  transferFromExpectSuccess,20  burnItemExpectSuccess,21} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {27  it('Execute the extrinsic and check nftItemList - owner of token', async () => {28    await usingApi(async (api: ApiPromise) => {29      const Alice = privateKey('//Alice');30      const Bob = privateKey('//Bob');31      const Charlie = privateKey('//Charlie');32      // nft33      const nftCollectionId = await createCollectionExpectSuccess();34      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');35      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3637      await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3839      // fungible40      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});41      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');42      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);43      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');44      // reFungible45      const reFungibleCollectionId = await46        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});47      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');48      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);49      await transferFromExpectSuccess(reFungibleCollectionId,50        newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');51    });52  });5354  it('Should reduce allowance if value is big', async () => {55    await usingApi(async () => {56      const alice = privateKey('//Alice');57      const bob = privateKey('//Bob');58      const charlie = privateKey('//Charlie');5960      // fungible61      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});62      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });6364      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);65      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');66      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');67    });68  });69});7071describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {72  it('transferFrom for a collection that does not exist', async () => {73    await usingApi(async (api: ApiPromise) => {74      const Alice = privateKey('//Alice');75      const Bob = privateKey('//Bob');76      const Charlie = privateKey('//Charlie');77      // nft78      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;79      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);8081      await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);8283      // fungible84      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;85      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);8687      await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);88      // reFungible89      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;90      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);9192      await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);93    });94  });9596  /* it('transferFrom for a collection that was destroyed', async () => {97    await usingApi(async (api: ApiPromise) => {98      this test copies approve negative test99    });100  }); */101102  /* it('transferFrom a token that does not exist', async () => {103    await usingApi(async (api: ApiPromise) => {104      this test copies approve negative test105    });106  }); */107108  /* it('transferFrom a token that was deleted', async () => {109    await usingApi(async (api: ApiPromise) => {110      this test copies approve negative test111    });112  }); */113114  it('transferFrom for not approved address', async () => {115    await usingApi(async (api: ApiPromise) => {116      const Alice = privateKey('//Alice');117      const Bob = privateKey('//Bob');118      const Charlie = privateKey('//Charlie');119      // nft120      const nftCollectionId = await createCollectionExpectSuccess();121      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');122123      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);124125      // fungible126      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});127      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');128      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);129      // reFungible130      const reFungibleCollectionId = await131        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});132      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');133      await transferFromExpectFail(reFungibleCollectionId,134        newReFungibleTokenId, Bob, Alice, Charlie, 1);135    });136  });137138  it('transferFrom incorrect token count', async () => {139    await usingApi(async (api: ApiPromise) => {140      const Alice = privateKey('//Alice');141      const Bob = privateKey('//Bob');142      const Charlie = privateKey('//Charlie');143      // nft144      const nftCollectionId = await createCollectionExpectSuccess();145      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');146      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);147148      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);149150      // fungible151      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});152      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');153      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);154      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);155      // reFungible156      const reFungibleCollectionId = await157        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});158      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');159      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);160      await transferFromExpectFail(reFungibleCollectionId,161        newReFungibleTokenId, Bob, Alice, Charlie, 2);162    });163  });164165  it('execute transferFrom from account that is not owner of collection', async () => {166    await usingApi(async (api: ApiPromise) => {167      const Alice = privateKey('//Alice');168      const Bob = privateKey('//Bob');169      const Charlie = privateKey('//Charlie');170      const Dave = privateKey('//Dave');171      // nft172      const nftCollectionId = await createCollectionExpectSuccess();173      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');174      try {175        await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);176        await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);177      } catch (e) {178        // tslint:disable-next-line:no-unused-expression179        expect(e).to.be.exist;180      }181182      // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);183184      // fungible185      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});186      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');187      try {188        await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);189        await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);190      } catch (e) {191        // tslint:disable-next-line:no-unused-expression192        expect(e).to.be.exist;193      }194      // reFungible195      const reFungibleCollectionId = await196        createCollectionExpectSuccess({mode: {type: 'ReFungible'}});197      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');198      try {199        await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);200        await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);201      } catch (e) {202        // tslint:disable-next-line:no-unused-expression203        expect(e).to.be.exist;204      }205    });206  });207  it( 'transferFrom burnt token before approve NFT', async () => {208    await usingApi(async (api: ApiPromise) => {209      const Alice = privateKey('//Alice');210      const Bob = privateKey('//Bob');211      const Charlie = privateKey('//Charlie');212      // nft213      const nftCollectionId = await createCollectionExpectSuccess();214      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');215      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);216      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);217      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      218    });219  });220  it( 'transferFrom burnt token before approve Fungible', async () => {221    await usingApi(async (api: ApiPromise) => {222    const Alice = privateKey('//Alice');223      const Bob = privateKey('//Bob');224      const Charlie = privateKey('//Charlie');225      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});226      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');227      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);228      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);229      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);230          231    });232  }); 233  it( 'transferFrom burnt token before approve ReFungible', async () => {234    await usingApi(async (api: ApiPromise) => {235    const Alice = privateKey('//Alice');236      const Bob = privateKey('//Bob');237      const Charlie = privateKey('//Charlie');238      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});239      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');240      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);241      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);242      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);243          244    });245  });246  247  it( 'transferFrom burnt token after approve NFT', async () => {248    await usingApi(async (api: ApiPromise) => {249      const Alice = privateKey('//Alice');250      const Bob = privateKey('//Bob');251      const Charlie = privateKey('//Charlie');252      // nft253      const nftCollectionId = await createCollectionExpectSuccess();254      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');255      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);256      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);257      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      258    });259  });260  it( 'transferFrom burnt token after approve Fungible', async () => {261    await usingApi(async (api: ApiPromise) => {262    const Alice = privateKey('//Alice');263      const Bob = privateKey('//Bob');264      const Charlie = privateKey('//Charlie');265      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});266      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');267      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);268      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);269      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);270          271    });272  }); 273  it( 'transferFrom burnt token after approve ReFungible', async () => {274    await usingApi(async (api: ApiPromise) => {275    const Alice = privateKey('//Alice');276      const Bob = privateKey('//Bob');277      const Charlie = privateKey('//Charlie');278      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});279      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');280      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);281      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);282      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);283          284    });285  }); 286});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -21,6 +21,8 @@
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
+export const U128_MAX = (1n << 128n) - 1n;
+
 type GenericResult = {
   success: boolean,
 };
@@ -238,6 +240,13 @@
   return unused;
 }
 
+export async function getAllowance(collectionId: number, tokenId: number, owner: string, approved: string) {
+  return await usingApi(async (api) => {
+    const bn = await api.query.nft.allowances(collectionId, [tokenId, owner, approved]) as unknown as BN;
+    return BigInt(bn.toString());
+  });
+}
+
 export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {
   return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));
 }
@@ -479,18 +488,20 @@
   });
 }
 
-export interface CreateFungibleData extends Struct {
-  readonly value: u128;
+export interface CreateFungibleData {
+  readonly Value: bigint;
 }
 
-export interface CreateReFungibleData extends Struct {}
-export interface CreateNftData extends Struct {}
+export interface CreateReFungibleData { }
+export interface CreateNftData { }
 
-export interface CreateItemData extends Enum {
+export type CreateItemData = {
   NFT: CreateNftData;
+} | {
   Fungible: CreateFungibleData;
+} | {
   ReFungible: CreateReFungibleData;
-}
+};
 
 export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
   await usingApi(async (api) => {
@@ -510,7 +521,7 @@
 
 export async function
 approveExpectSuccess(collectionId: number,
-                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob
+                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) {
   await usingApi(async (api: ApiPromise) => {
     const allowanceBefore =
       await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
@@ -521,17 +532,17 @@
     expect(result.success).to.be.true;
     const allowanceAfter =
       await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
-    expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);
+    expect(allowanceAfter.sub(allowanceBefore).toString()).to.be.equal(amount.toString());
   });
 }
 
 export async function
 transferFromExpectSuccess(collectionId: number,
                           tokenId: number,
-                          accountApproved: IKeyringPair, //bob
-                          accountFrom: IKeyringPair, //alice
-                          accountTo: IKeyringPair, //charlie
-                          value: number = 1,
+                          accountApproved: IKeyringPair,
+                          accountFrom: IKeyringPair,
+                          accountTo: IKeyringPair,
+                          value: number | bigint = 1,
                           type: string = 'NFT') {
   await usingApi(async (api: ApiPromise) => {
     let balanceBefore = new BN(0);
@@ -550,7 +561,7 @@
     }
     if (type === 'Fungible') {
       const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;
-      expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);
+      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
     }
     if (type === 'ReFungible') {
       const nftItemData =
@@ -567,7 +578,7 @@
                        accountApproved: IKeyringPair,
                        accountFrom: IKeyringPair,
                        accountTo: IKeyringPair,
-                       value: number = 1) {
+                       value: number | bigint = 1) {
   await usingApi(async (api: ApiPromise) => {
     const transferFromTx = await api.tx.nft.transferFrom(
       accountFrom.address, accountTo.address, collectionId, tokenId, value);
@@ -583,7 +594,7 @@
                       tokenId: number,
                       sender: IKeyringPair,
                       recipient: IKeyringPair,
-                      value: number = 1,
+                      value: number | bigint = 1,
                       type: string = 'NFT') {
   await usingApi(async (api: ApiPromise) => {
     let balanceBefore = new BN(0);
@@ -601,7 +612,7 @@
     }
     if (type === 'Fungible') {
       const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;
-      expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);
+      expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
     }
     if (type === 'ReFungible') {
       const nftItemData =
@@ -617,7 +628,7 @@
                    tokenId: number,
                    sender: IKeyringPair,
                    recipient: IKeyringPair,
-                   value: number = 1,
+                   value: number | bigint = 1,
                    type: string = 'NFT') {
   await usingApi(async (api: ApiPromise) => {
     const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
@@ -632,7 +643,7 @@
 
 export async function
 approveExpectFail(collectionId: number,
-                  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
+                  tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) {
   await usingApi(async (api: ApiPromise) => {
     const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);
     const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;
@@ -642,6 +653,33 @@
   });
 }
 
+export async function getFungibleBalance(
+  collectionId: number,
+  owner: string,
+) {
+  return await usingApi(async (api) => {
+    const response = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON() as unknown as {Value: string};
+    return BigInt(response.Value);
+  });
+}
+
+export async function createFungibleItemExpectSuccess(
+  sender: IKeyringPair,
+  collectionId: number,
+  data: CreateFungibleData,
+  owner: string = sender.address,
+) {
+  return await usingApi(async (api) => {
+    const tx = api.tx.nft.createItem(collectionId, owner, { Fungible: data });
+
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getCreateItemResult(events);
+
+    expect(result.success).to.be.true;
+    return result.itemId;
+  });
+}
+
 export async function createItemExpectSuccess(
   sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
   let newItemId: number = 0;
modifiedtests/yarn.lockdiffbeforeafterboth
--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -4710,7 +4710,7 @@
   dependencies:
     ci-info "^2.0.0"
 
-is-core-module@^2.1.0:
+is-core-module@^2.2.0:
   version "2.2.0"
   resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
   integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
@@ -7110,11 +7110,11 @@
   integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
 
 resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0, resolve@^1.3.2:
-  version "1.19.0"
-  resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
-  integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
+  version "1.20.0"
+  resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
+  integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
   dependencies:
-    is-core-module "^2.1.0"
+    is-core-module "^2.2.0"
     path-parse "^1.0.6"
 
 responselike@^1.0.2: