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

difftreelog

test(eth) fix linting errors and warnings

Fahrrader2022-09-05parent: #e6b5df4.patch.diff
in: master

8 files changed

modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -15,7 +15,7 @@
 
 import {expect} from 'chai';
 import privateKey from '../substrate/privateKey';
-import { UNIQUE } from '../util/helpers';
+import {UNIQUE} from '../util/helpers';
 import {
   createEthAccount,
   createEthAccountWithBalance, 
@@ -24,7 +24,6 @@
   getCollectionAddressFromResult, 
   itWeb3,
   recordEthFee,
-  subToEth,
 } from './util/helpers';
 
 describe('Add collection admins', () => {
@@ -37,7 +36,7 @@
       .send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
 
-    const newAdmin = await createEthAccount(web3);
+    const newAdmin = createEthAccount(web3);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
     await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
     const adminList = await api.rpc.unique.adminlist(collectionId);
@@ -92,7 +91,7 @@
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
     await collectionEvm.methods.addCollectionAdmin(admin).send();
     
-    const user = await createEthAccount(web3);
+    const user = createEthAccount(web3);
     await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))
       .to.be.rejectedWith('NoPermission');
 
@@ -114,7 +113,7 @@
     const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
     
-    const user = await createEthAccount(web3);
+    const user = createEthAccount(web3);
     await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))
       .to.be.rejectedWith('NoPermission');
 
@@ -175,7 +174,7 @@
       .send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
 
-    const newAdmin = await createEthAccount(web3);
+    const newAdmin = createEthAccount(web3);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
     await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
     {
@@ -226,7 +225,7 @@
 
     const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     await collectionEvm.methods.addCollectionAdmin(admin0).send();
-    const admin1 = await createEthAccount(web3);
+    const admin1 = createEthAccount(web3);
     await collectionEvm.methods.addCollectionAdmin(admin1).send();
 
     await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))
@@ -253,7 +252,7 @@
 
     const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     await collectionEvm.methods.addCollectionAdmin(admin).send();
-    const notAdmin = await createEthAccount(web3);
+    const notAdmin = createEthAccount(web3);
 
     await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))
       .to.be.rejectedWith('NoPermission');
modifiedtests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,5 +1,5 @@
 import {addToAllowListExpectSuccess, bigIntToSub, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess} from '../util/helpers';
-import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub, subToEth} from './util/helpers';
+import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub} from './util/helpers';
 import nonFungibleAbi from './nonFungibleAbi.json';
 import {expect} from 'chai';
 import {evmToAddress} from '@polkadot/util-crypto';
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
before · tests/src/eth/createNFTCollection.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {evmToAddress} from '@polkadot/util-crypto';18import {expect} from 'chai';19import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';20import {21  evmCollectionHelpers,22  collectionIdToAddress,23  createEthAccount,24  createEthAccountWithBalance,25  evmCollection,26  itWeb3,27  getCollectionAddressFromResult,28} from './util/helpers';2930describe('Create NFT collection from EVM', () => {31  itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {32    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);33    const collectionHelper = evmCollectionHelpers(web3, owner);34    const collectionName = 'CollectionEVM';35    const description = 'Some description';36    const tokenPrefix = 'token prefix';37  38    const collectionCountBefore = await getCreatedCollectionCount(api);39    const result = await collectionHelper.methods40      .createNonfungibleCollection(collectionName, description, tokenPrefix)41      .send();42    const collectionCountAfter = await getCreatedCollectionCount(api);43  44    const {collectionId, collection} = await getCollectionAddressFromResult(api, result);45    expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);46    expect(collectionId).to.be.eq(collectionCountAfter);47    expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);48    expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);49    expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);50    expect(collection.mode.isNft).to.be.true;51  });5253  itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {54    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);55    const collectionHelpers = evmCollectionHelpers(web3, owner);56  57    const expectedCollectionId = await getCreatedCollectionCount(api) + 1;58    const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);59    expect(await collectionHelpers.methods60      .isCollectionExist(expectedCollectionAddress)61      .call()).to.be.false;6263    await collectionHelpers.methods64      .createNonfungibleCollection('A', 'A', 'A')65      .send();66    67    expect(await collectionHelpers.methods68      .isCollectionExist(expectedCollectionAddress)69      .call()).to.be.true;70  });71  72  itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {73    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);74    const collectionHelpers = evmCollectionHelpers(web3, owner);75    let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();76    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);77    const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);78    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);79    result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();80    let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;81    expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;82    const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;83    expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));84    await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');85    const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);86    await sponsorCollection.methods.confirmCollectionSponsorship().send();87    collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;88    expect(collectionSub.sponsorship.isConfirmed).to.be.true;89    expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));90  });9192  itWeb3('Set limits', async ({api, web3, privateKeyWrapper}) => {93    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);94    const collectionHelpers = evmCollectionHelpers(web3, owner);95    const result = await collectionHelpers.methods.createNonfungibleCollection('Const collection', '5', '5').send();96    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);97    const limits = {98      accountTokenOwnershipLimit: 1000,99      sponsoredDataSize: 1024,100      sponsoredDataRateLimit: 30,101      tokenLimit: 1000000,102      sponsorTransferTimeout: 6,103      sponsorApproveTimeout: 6,104      ownerCanTransfer: false,105      ownerCanDestroy: false,106      transfersEnabled: false,107    };108109    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);110    await collectionEvm.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();111    await collectionEvm.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();112    await collectionEvm.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();113    await collectionEvm.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();114    await collectionEvm.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();115    await collectionEvm.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();116    await collectionEvm.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();117    await collectionEvm.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();118    await collectionEvm.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();119    120    const collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;121    expect(collectionSub.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);122    expect(collectionSub.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);123    expect(collectionSub.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit);124    expect(collectionSub.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);125    expect(collectionSub.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);126    expect(collectionSub.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);127    expect(collectionSub.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);128    expect(collectionSub.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);129    expect(collectionSub.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);130  });131132  itWeb3('Collection address exist', async ({api, web3, privateKeyWrapper}) => {133    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);134    const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';135    const collectionHelpers = evmCollectionHelpers(web3, owner);136    expect(await collectionHelpers.methods137      .isCollectionExist(collectionAddressForNonexistentCollection).call())138      .to.be.false;139    140    const result = await collectionHelpers.methods.createNonfungibleCollection('Collection address exist', '7', '7').send();141    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);142    expect(await collectionHelpers.methods143      .isCollectionExist(collectionIdAddress).call())144      .to.be.true;145  });146});147148describe('(!negative tests!) Create NFT collection from EVM', () => {149  itWeb3('(!negative test!) Create collection (bad lengths)', async ({api, web3, privateKeyWrapper}) => {150    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);151    const helper = evmCollectionHelpers(web3, owner);152    {153      const MAX_NAME_LENGHT = 64;154      const collectionName = 'A'.repeat(MAX_NAME_LENGHT + 1);155      const description = 'A';156      const tokenPrefix = 'A';157    158      await expect(helper.methods159        .createNonfungibleCollection(collectionName, description, tokenPrefix)160        .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGHT);161      162    }163    {  164      const MAX_DESCRIPTION_LENGHT = 256;165      const collectionName = 'A';166      const description = 'A'.repeat(MAX_DESCRIPTION_LENGHT + 1);167      const tokenPrefix = 'A';168      await expect(helper.methods169        .createNonfungibleCollection(collectionName, description, tokenPrefix)170        .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGHT);171    }172    {  173      const MAX_TOKEN_PREFIX_LENGHT = 16;174      const collectionName = 'A';175      const description = 'A';176      const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGHT + 1);177      await expect(helper.methods178        .createNonfungibleCollection(collectionName, description, tokenPrefix)179        .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGHT);180    }181  });182  183  itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {184    const owner = await createEthAccount(web3);185    const helper = evmCollectionHelpers(web3, owner);186    const collectionName = 'A';187    const description = 'A';188    const tokenPrefix = 'A';189    190    await expect(helper.methods191      .createNonfungibleCollection(collectionName, description, tokenPrefix)192      .call()).to.be.rejectedWith('NotSufficientFounds');193  });194195  itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {196    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);197    const notOwner = await createEthAccount(web3);198    const collectionHelpers = evmCollectionHelpers(web3, owner);199    const result = await collectionHelpers.methods.createNonfungibleCollection('A', 'A', 'A').send();200    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);201    const contractEvmFromNotOwner = evmCollection(web3, notOwner, collectionIdAddress);202    const EXPECTED_ERROR = 'NoPermission';203    {204      const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);205      await expect(contractEvmFromNotOwner.methods206        .setCollectionSponsor(sponsor)207        .call()).to.be.rejectedWith(EXPECTED_ERROR);208      209      const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);210      await expect(sponsorCollection.methods211        .confirmCollectionSponsorship()212        .call()).to.be.rejectedWith('caller is not set as sponsor');213    }214    {215      await expect(contractEvmFromNotOwner.methods216        .setCollectionLimit('account_token_ownership_limit', '1000')217        .call()).to.be.rejectedWith(EXPECTED_ERROR);218    }219  });220221  itWeb3('(!negative test!) Set limits', async ({api, web3, privateKeyWrapper}) => {222    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);223    const collectionHelpers = evmCollectionHelpers(web3, owner);224    const result = await collectionHelpers.methods.createNonfungibleCollection('Schema collection', 'A', 'A').send();225    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);226    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);227    await expect(collectionEvm.methods228      .setCollectionLimit('badLimit', 'true')229      .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');230  });231});
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -189,7 +189,7 @@
   });
   
   itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
-    const owner = await createEthAccount(web3);
+    const owner = createEthAccount(web3);
     const helper = evmCollectionHelpers(web3, owner);
     const collectionName = 'A';
     const description = 'A';
@@ -202,7 +202,7 @@
 
   itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-    const notOwner = await createEthAccount(web3);
+    const notOwner = createEthAccount(web3);
     const collectionHelpers = evmCollectionHelpers(web3, owner);
     const result = await collectionHelpers.methods.createRefungibleCollection('A', 'A', 'A').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
modifiedtests/src/eth/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nesting/nest.test.ts
+++ b/tests/src/eth/nesting/nest.test.ts
@@ -1,7 +1,7 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {Contract} from 'web3-eth-contract';
 
-import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds'
+import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds';
 
 const createNestingCollection = async (
   helper: EthUniqueHelper,
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
modifiedtests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -33,7 +33,7 @@
     await helper.disconnectWeb3();
     silentConsole.disable();
   }
-}
+};
   
 export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
   let i: any = it;
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -38,18 +38,18 @@
 class ContractGroup extends EthGroupBase {
   async findImports(imports?: ContractImports[]){
     if(!imports) return function(path: string) {
-      return {error: 'File not found'};
+      return {error: `File not found: ${path}`};
     };
   
     const knownImports = {} as any;
-    for(let imp of imports) {
+    for(const imp of imports) {
       knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();
     }
   
     return function(path: string) {
-      if(knownImports.hasOwnProperty(path)) return {contents: knownImports[path]};
-      return {error: 'File not found'};
-    }
+      if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};
+      return {error: `File not found: ${path}`};
+    };
   }
 
   async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {
@@ -85,7 +85,7 @@
     const contract = new web3.eth.Contract(abi, undefined, {
       data: object,
       from: signer,
-      gas: this.helper.eth.DEFAULT_GAS
+      gas: this.helper.eth.DEFAULT_GAS,
     });
     return await contract.deploy({data: object}).send({from: signer});
   }
@@ -108,7 +108,7 @@
     const abi = {
       'nft': nonFungibleAbi,
       'rft': refungibleAbi,
-      'ft': fungibleAbi
+      'ft': fungibleAbi,
     }[mode];
     const web3 = this.helper.getWeb3();
     return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
@@ -154,7 +154,7 @@
     await this.helper.executeExtrinsic(
       signer,
       'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],
-      true, `Unable to perform evm.call`
+      true, 'Unable to perform evm.call',
     );
   }