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
before · tests/src/approve.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 } from './substrate/substrate-api';11import {12  approveExpectFail,13  approveExpectSuccess,14  createCollectionExpectSuccess,15  createItemExpectSuccess,16  destroyCollectionExpectSuccess,17} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {23  it('Execute the extrinsic and check approvedList', async () => {24    await usingApi(async (api: ApiPromise) => {25      const Alice = privateKey('//Alice');26      const Bob = privateKey('//Bob');27      const nftCollectionId = await createCollectionExpectSuccess();28      // nft29      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');30      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);31      // fungible32      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});33      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');34      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);35      // reFungible36      const reFungibleCollectionId =37        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});38      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');39      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);40    });41  });4243  it('Remove approval by using 0 amount', async () => {44    await usingApi(async (api: ApiPromise) => {45      const Alice = privateKey('//Alice');46      const Bob = privateKey('//Bob');47      const nftCollectionId = await createCollectionExpectSuccess();48      // nft49      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');50      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);51      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);52      // fungible53      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});54      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');55      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);56      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);57      // reFungible58      const reFungibleCollectionId =59        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});60      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');61      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);62      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);63    });64  });65});6667describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {68  it('Approve for a collection that does not exist', async () => {69    await usingApi(async (api: ApiPromise) => {70      const Alice = privateKey('//Alice');71      const Bob = privateKey('//Bob');72      // nft73      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;74      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);75      // fungible76      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;77      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);78      // reFungible79      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;80      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);81    });82  });8384  it('Approve for a collection that was destroyed', async () => {85    await usingApi(async (api: ApiPromise) => {86      const Alice = privateKey('//Alice');87      const Bob = privateKey('//Bob');88      // nft89      const nftCollectionId = await createCollectionExpectSuccess();90      await destroyCollectionExpectSuccess(nftCollectionId);91      await approveExpectFail(nftCollectionId, 1, Alice, Bob);92      // fungible93      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});94      await destroyCollectionExpectSuccess(fungibleCollectionId);95      await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);96      // reFungible97      const reFungibleCollectionId =98        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});99      await destroyCollectionExpectSuccess(reFungibleCollectionId);100      await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);101    });102  });103104  it('Approve transfer of a token that does not exist', async () => {105    await usingApi(async (api: ApiPromise) => {106      const Alice = privateKey('//Alice');107      const Bob = privateKey('//Bob');108      // nft109      const nftCollectionId = await createCollectionExpectSuccess();110      await approveExpectFail(nftCollectionId, 2, Alice, Bob);111      // fungible112      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});113      await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);114      // reFungible115      const reFungibleCollectionId =116        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});117      await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);118    });119  });120121  it('Approve using the address that does not own the approved token', async () => {122    await usingApi(async (api: ApiPromise) => {123      const Alice = privateKey('//Alice');124      const Bob = privateKey('//Bob');125      const nftCollectionId = await createCollectionExpectSuccess();126      // nft127      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');128      await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);129      // fungible130      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});131      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');132      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);133      // reFungible134      const reFungibleCollectionId =135        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});136      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');137      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);138    });139  });140});
after · tests/src/approve.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 } from './substrate/substrate-api';11import {12  approveExpectFail,13  approveExpectSuccess,14  createCollectionExpectSuccess,15  createFungibleItemExpectSuccess,16  createItemExpectSuccess,17  destroyCollectionExpectSuccess,18  transferFromExpectSuccess,19  U128_MAX,20} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {26  it('Execute the extrinsic and check approvedList', async () => {27    await usingApi(async (api: ApiPromise) => {28      const Alice = privateKey('//Alice');29      const Bob = privateKey('//Bob');30      const nftCollectionId = await createCollectionExpectSuccess();31      // nft32      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');33      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);34      // fungible35      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});36      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');37      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);38      // reFungible39      const reFungibleCollectionId =40        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});41      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');42      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);43    });44  });4546  it('Remove approval by using 0 amount', async () => {47    await usingApi(async (api: ApiPromise) => {48      const Alice = privateKey('//Alice');49      const Bob = privateKey('//Bob');50      const nftCollectionId = await createCollectionExpectSuccess();51      // nft52      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');53      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);54      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);55      // fungible56      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});57      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');58      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);59      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);60      // reFungible61      const reFungibleCollectionId =62        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});63      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');64      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);65      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);66    });67  });68});6970describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {71  it('Approve for a collection that does not exist', async () => {72    await usingApi(async (api: ApiPromise) => {73      const Alice = privateKey('//Alice');74      const Bob = privateKey('//Bob');75      // nft76      const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;77      await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);78      // fungible79      const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;80      await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);81      // reFungible82      const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;83      await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);84    });85  });8687  it('Approve for a collection that was destroyed', async () => {88    await usingApi(async (api: ApiPromise) => {89      const Alice = privateKey('//Alice');90      const Bob = privateKey('//Bob');91      // nft92      const nftCollectionId = await createCollectionExpectSuccess();93      await destroyCollectionExpectSuccess(nftCollectionId);94      await approveExpectFail(nftCollectionId, 1, Alice, Bob);95      // fungible96      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});97      await destroyCollectionExpectSuccess(fungibleCollectionId);98      await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);99      // reFungible100      const reFungibleCollectionId =101        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});102      await destroyCollectionExpectSuccess(reFungibleCollectionId);103      await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);104    });105  });106107  it('Approve transfer of a token that does not exist', async () => {108    await usingApi(async (api: ApiPromise) => {109      const Alice = privateKey('//Alice');110      const Bob = privateKey('//Bob');111      // nft112      const nftCollectionId = await createCollectionExpectSuccess();113      await approveExpectFail(nftCollectionId, 2, Alice, Bob);114      // fungible115      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});116      await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);117      // reFungible118      const reFungibleCollectionId =119        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});120      await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);121    });122  });123124  it('Approve using the address that does not own the approved token', async () => {125    await usingApi(async (api: ApiPromise) => {126      const Alice = privateKey('//Alice');127      const Bob = privateKey('//Bob');128      const nftCollectionId = await createCollectionExpectSuccess();129      // nft130      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');131      await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);132      // fungible133      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});134      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');135      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);136      // reFungible137      const reFungibleCollectionId =138        await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});139      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');140      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);141    });142  });143});
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
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -11,8 +11,10 @@
   approveExpectFail,
   approveExpectSuccess,
   createCollectionExpectSuccess,
+  createFungibleItemExpectSuccess,
   createItemExpectSuccess,
   destroyCollectionExpectSuccess,
+  getAllowance,
   transferFromExpectFail,
   transferFromExpectSuccess,
   burnItemExpectSuccess,
@@ -48,6 +50,22 @@
         newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');
     });
   });
+
+  it('Should reduce allowance if value is big', async () => {
+    await usingApi(async () => {
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const charlie = privateKey('//Charlie');
+
+      // fungible
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      const newFungibleTokenId = await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 500000n });
+
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob, 500000n);
+      await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, bob, alice, charlie, 500000n, 'Fungible');
+      expect((await getAllowance(fungibleCollectionId, newFungibleTokenId, alice.address, bob.address)).toString()).to.equal('0');
+    });
+  });
 });
 
 describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {
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: