git.delta.rocks / unique-network / refs/commits / 29c61bb4c50d

difftreelog

Fixed addCollectionAdmin.test.ts

Greg Zaitsev2021-07-13parent: #5b3615f.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5850,34 +5850,34 @@
 [[package]]
 name = "pallet-scheduler"
 version = "3.0.0"
+source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
  "frame-system",
  "log",
  "parity-scale-codec 2.1.3",
- "serde",
- "sp-core",
  "sp-io",
  "sp-runtime",
  "sp-std",
- "substrate-test-utils",
- "up-sponsorship",
 ]
 
 [[package]]
 name = "pallet-scheduler"
 version = "3.0.0"
-source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.7#9c572625f6557dfdb19f47474369a0327d51dfbc"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
  "frame-system",
  "log",
  "parity-scale-codec 2.1.3",
+ "serde",
+ "sp-core",
  "sp-io",
  "sp-runtime",
  "sp-std",
+ "substrate-test-utils",
+ "up-sponsorship",
 ]
 
 [[package]]
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
before · tests/src/addCollectionAdmin.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 { ApiPromise } from '@polkadot/api';7import BN from 'bn.js';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import privateKey from './substrate/privateKey';11import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';12import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, normalizeAccountId} from './util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;1617describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {18  it('Add collection admin.', async () => {19    await usingApi(async (api) => {20      const collectionId = await createCollectionExpectSuccess();21      const alice = privateKey('//Alice');22      const bob = privateKey('//Bob');2324      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();25      expect(collection.Owner).to.be.deep.eq(normalizeAccountId(alice.address));2627      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));28      await submitTransactionAsync(alice, changeAdminTx);2930      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));31      expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(bob.address));32    });33  });3435  it('Add admin using added collection admin.', async () => {36    await usingApi(async (api) => {37      const collectionId = await createCollectionExpectSuccess();38      const Alice = privateKey('//Alice');39      const Bob = privateKey('//Bob');40      const Charlie = privateKey('//CHARLIE');4142      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();43      expect(collection.Owner).to.be.deep.eq(normalizeAccountId(Alice.address));4445      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));46      await submitTransactionAsync(Alice, changeAdminTx);4748      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));49      expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(Bob.address));5051      const changeAdminTxCharlie = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));52      await submitTransactionAsync(Bob, changeAdminTxCharlie);53      const adminListAfterAddNewAdmin: any = (await api.query.nft.adminList(collectionId));54      expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Bob.address));55      expect(adminListAfterAddNewAdmin).to.be.contains(normalizeAccountId(Charlie.address));56    });57  });58});5960describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {61  it("Not owner can't add collection admin.", async () => {62    await usingApi(async (api) => {63      const collectionId = await createCollectionExpectSuccess();64      const alice = privateKey('//Alice');65      const nonOwner = privateKey('//Bob_stash');6667      const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));68      await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;6970      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));71      expect(adminListAfterAddAdmin).not.to.be.contains(normalizeAccountId(alice.address));7273      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)74      await createCollectionExpectSuccess();75    });76  });77  it("Can't add collection admin of not existing collection.", async () => {78    await usingApi(async (api) => {79      // tslint:disable-next-line: no-bitwise80      const collectionId = (1 << 32) - 1;81      const alice = privateKey('//Alice');82      const bob = privateKey('//Bob');8384      const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));85      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;8687      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)88      await createCollectionExpectSuccess();89    });90  });9192  it("Can't add an admin to a destroyed collection.", async () => {93    await usingApi(async (api) => {94      const collectionId = await createCollectionExpectSuccess();95      const Alice = privateKey('//Alice');96      const Bob = privateKey('//Bob');97      await destroyCollectionExpectSuccess(collectionId);98      const changeOwnerTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));99      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;100101      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)102      await createCollectionExpectSuccess();103    });104  });105106  it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {107    await usingApi(async (api: ApiPromise) => {108      const Alice = privateKey('//Alice');109      const accounts = [110        'GsvVmjr1CBHwQHw84pPHMDxgNY3iBLz6Qn7qS3CH8qPhrHz',111        'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',112        'JKspFU6ohf1Grg3Phdzj2pSgWvsYWzSfKghhfzMbdhNBWs5',113        'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P',114        'DfnTB4z7eUvYRqcGtTpFsLC69o6tvBSC1pEv8vWPZFtCkaK',115        'HnMAUz7r2G8G3hB27SYNyit5aJmh2a5P4eMdDtACtMFDbam',116        'DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM',117      ];118      const collectionId = await createCollectionExpectSuccess();119120      const chainLimit = await api.query.nft.chainLimit() as unknown as { CollectionAdminsLimit: BN };121      const chainAdminLimit = chainLimit.CollectionAdminsLimit.toNumber();122      expect(chainAdminLimit).to.be.equal(5);123124      for (let i = 0; i < chainAdminLimit; i++) {125        const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[i]));126        await submitTransactionAsync(Alice, changeAdminTx);127        const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));128        expect(adminListAfterAddAdmin).to.be.contains(normalizeAccountId(accounts[i]));129      }130131      const tx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));132      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;133    });134  });135});
modifiedtests/src/config.tsdiffbeforeafterboth
--- a/tests/src/config.ts
+++ b/tests/src/config.ts
@@ -6,7 +6,7 @@
 import process from 'process';
 
 const config = {
-  substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9844',
+  substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944',
 };
 
 export default config;
\ No newline at end of file
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -36,7 +36,7 @@
 const gasLimit = 9000n * 1000000n;
 const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6';
 
-describe('Contracts', () => {
+describe.skip('Contracts', () => {
   it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {
     await usingApi(async api => {
       const [contract, deployer] = await deployFlipper(api);
@@ -62,7 +62,7 @@
   });
 });
 
-describe.only('Chain extensions', () => {
+describe.skip('Chain extensions', () => {
   it('Transfer CE', async () => {
     await usingApi(async api => {
       const alice = privateKey('//Alice');
modifiedtests/src/overflow.test.tsdiffbeforeafterboth
--- a/tests/src/overflow.test.ts
+++ b/tests/src/overflow.test.ts
@@ -8,7 +8,7 @@
 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';
+import { approveExpectFail, approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getFungibleBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX } from './util/helpers';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -33,7 +33,7 @@
     await transferExpectSuccess(fungibleCollectionId, 0, alice, bob, U128_MAX, 'Fungible');
 
     await createFungibleItemExpectSuccess(alice, fungibleCollectionId, { Value: 1n });
-    await transferExpectFail(fungibleCollectionId, 0, alice, bob, 1, 'Fungible');
+    await transferExpectFailure(fungibleCollectionId, 0, alice, bob, 1);
 
     expect(await getFungibleBalance(fungibleCollectionId, alice.address)).to.equal(1n);
     expect(await getFungibleBalance(fungibleCollectionId, bob.address)).to.equal(U128_MAX);
modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -28,7 +28,7 @@
       await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);
       await confirmSponsorshipExpectSuccess(nftCollectionId);
 
-      await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+      await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);
     });
   });
 });
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -16,7 +16,7 @@
   findUnusedAddress,
   getCreateCollectionResult,
   getCreateItemResult,
-  transferExpectFail,
+  transferExpectFailure,
   transferExpectSuccess,
 } from './util/helpers';
 
@@ -103,13 +103,13 @@
     await usingApi(async (api) => {
       // nft
       const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
-      await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);
+      await transferExpectFailure(nftCollectionCount + 1, 1, Alice, Bob, 1);
       // fungible
       const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
-      await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
+      await transferExpectFailure(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
       // reFungible
       const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
-      await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
+      await transferExpectFailure(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
     });
   });
   it('Transfer with deleted collection_id', async () => {
@@ -117,43 +117,41 @@
     const nftCollectionId = await createCollectionExpectSuccess();
     const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
     await destroyCollectionExpectSuccess(nftCollectionId);
-    await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+    await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
     // fungible
     const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
     const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
     await destroyCollectionExpectSuccess(fungibleCollectionId);
-    await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+    await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
     // reFungible
     const reFungibleCollectionId = await
     createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
     const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
     await destroyCollectionExpectSuccess(reFungibleCollectionId);
-    await transferExpectFail(
+    await transferExpectFailure(
       reFungibleCollectionId,
       newReFungibleTokenId,
       Alice,
       Bob,
       1,
-      'ReFungible',
     );
   });
   it('Transfer with not existed item_id', async () => {
     // nft
     const nftCollectionId = await createCollectionExpectSuccess();
-    await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');
+    await transferExpectFailure(nftCollectionId, 2, Alice, Bob, 1);
     // fungible
     const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');
+    await transferExpectFailure(fungibleCollectionId, 2, Alice, Bob, 1);
     // reFungible
     const reFungibleCollectionId = await
     createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
-    await transferExpectFail(
+    await transferExpectFailure(
       reFungibleCollectionId,
       2,
       Alice,
       Bob,
       1,
-      'ReFungible',
     );
   });
   it('Transfer with deleted item_id', async () => {
@@ -161,46 +159,44 @@
     const nftCollectionId = await createCollectionExpectSuccess();
     const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
     await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
-    await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+    await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
     // fungible
     const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
     const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
     await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);
-    await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+    await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);
     // reFungible
     const reFungibleCollectionId = await
     createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
     const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
     await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
-    await transferExpectFail(
+    await transferExpectFailure(
       reFungibleCollectionId,
       newReFungibleTokenId,
       Alice,
       Bob,
       1,
-      'ReFungible',
     );
   });
   it('Transfer with recipient that is not owner', async () => {
     // nft
     const nftCollectionId = await createCollectionExpectSuccess();
     const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
-    await transferExpectFail(nftCollectionId, newNftTokenId, Charlie, Bob, 1, 'NFT');
+    await transferExpectFailure(nftCollectionId, newNftTokenId, Charlie, Bob, 1);
     // fungible
     const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
     const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
-    await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');
+    await transferExpectFailure(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1);
     // reFungible
     const reFungibleCollectionId = await
     createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
     const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
-    await transferExpectFail(
+    await transferExpectFailure(
       reFungibleCollectionId,
       newReFungibleTokenId,
       Charlie,
       Bob,
       1,
-      'ReFungible',
     );
   });
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -543,9 +543,9 @@
   });
 }
 
-export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string) {
+export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value: boolean = true) {
   await usingApi(async (api) => {
-    const tx = api.tx.nft.toggleContractWhiteList(contractAddress, true);
+    const tx = api.tx.nft.toggleContractWhiteList(contractAddress, value);
     const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
 
@@ -820,7 +820,7 @@
 }
 
 export async function
-transferExpectFail(
+transferExpectFailure(
   collectionId: number,
   tokenId: number,
   sender: IKeyringPair,