git.delta.rocks / unique-network / refs/commits / 7f526e168d3e

difftreelog

Merge develop and remove unneeded usingApi

Greg Zaitsev2021-02-11parent: #1d6108d.patch.diff
in: master
(cherry picked from commit 0ccf6006f00210f190eb9d8393d86a6f68778bae)

6 files changed

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);
modifiedtests/src/overflow.test.tsdiffbeforeafterboth
before · tests/src/overflow.test.ts
1import { IKeyringPair } from "@polkadot/types/types";2import chai from 'chai';3import chaiAsPromised from "chai-as-promised";4import privateKey from "./substrate/privateKey";5import usingApi from "./substrate/substrate-api";6import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFail, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from "./util/helpers";78chai.use(chaiAsPromised);9const expect = chai.expect;1011describe('Integration Test fungible overflows', () => {12    let alice: IKeyringPair;13    let bob: IKeyringPair;14    let charlie: IKeyringPair;1516    before(async () => {17        await usingApi(async () => {18            alice = privateKey('//Alice');19            bob = privateKey('//Bob');20            charlie = privateKey('//Charlie');21        });22    });2324    it('fails when overflows on transfer', async () => {25        await usingApi(async () => {26            const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });2728            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });29            await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');3031            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });32            await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');3334            expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);35            expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);36        });37    });3839    it('fails on allowance overflow', async () => {40        await usingApi(async () => {41            const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });4243            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });44            await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);45            await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);46        });47    });4849    it('fails when overflows on transferFrom', async () => {50        await usingApi(async () => {51            const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });5253            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });54            await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);55            await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');5657            expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);58            expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);5960            await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });61            await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);62            await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);6364            expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);65            expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);66        });67    });68});
after · tests/src/overflow.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//56import { IKeyringPair } from "@polkadot/types/types";7import chai from 'chai';8import chaiAsPromised from "chai-as-promised";9import privateKey from "./substrate/privateKey";10import usingApi from "./substrate/substrate-api";11import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFail, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from "./util/helpers";1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('Integration Test fungible overflows', () => {17    let alice: IKeyringPair;18    let bob: IKeyringPair;19    let charlie: IKeyringPair;2021    before(async () => {22        await usingApi(async () => {23            alice = privateKey('//Alice');24            bob = privateKey('//Bob');25            charlie = privateKey('//Charlie');26        });27    });2829    it('fails when overflows on transfer', async () => {30        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });3132        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });33        await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');3435        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });36        await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');3738        expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);39        expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);40    });4142    it('fails on allowance overflow', async () => {43        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });4445        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });46        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);47        await approveExpectFail(fungibleCollectionId, 0, alice, bob, U128_MAX);48    });4950    it('fails when overflows on transferFrom', async () => {51        const fungibleCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });5253        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });54        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX);55        await transferFromExpectSuccess(fungibleCollectionId, 0, bob, alice, charlie, U128_MAX, 'Fungible');5657        expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);58        expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);5960        await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: U128_MAX });61        await approveExpectSuccess(fungibleCollectionId, 0, alice, bob, 1n);62        await transferFromExpectFail(fungibleCollectionId, 0, bob, alice, charlie, 1);6364        expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);65        expect(await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).to.equal(0n);66    });67});
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/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
@@ -247,6 +247,10 @@
   });
 }
 
+export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {
+  return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));
+}
+
 export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
   const totalNumber = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10) as unknown as number;
   const newCollection: number = totalNumber + 1;
@@ -517,7 +521,7 @@
 
 export async function
 approveExpectSuccess(collectionId: number,
-                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 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;
@@ -535,9 +539,9 @@
 export async function
 transferFromExpectSuccess(collectionId: number,
                           tokenId: number,
-                          accountApproved: IKeyringPair, //bob
-                          accountFrom: IKeyringPair, //alice
-                          accountTo: IKeyringPair, //charlie
+                          accountApproved: IKeyringPair,
+                          accountFrom: IKeyringPair,
+                          accountTo: IKeyringPair,
                           value: number | bigint = 1,
                           type: string = 'NFT') {
   await usingApi(async (api: ApiPromise) => {
modifiedtests/yarn.lockdiffbeforeafterboth
--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -4638,7 +4638,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==
@@ -7027,11 +7027,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: