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
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -181,7 +181,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';
@@ -194,7 +194,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.createNonfungibleCollection('A', 'A', 'A').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
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
before · tests/src/eth/util/playgrounds/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15chai.use(chaiAsPromised);16export const expect = chai.expect;1718export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19  const silentConsole = new SilentConsole();20  silentConsole.enable();2122  const helper = new EthUniqueHelper(new SilentLogger());2324  try {25    await helper.connect(config.substrateUrl);26    await helper.connectWeb3(config.substrateUrl);27    const ss58Format = helper.chain.getChainProperties().ss58Format;28    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);29    await code(helper, privateKey);30  }31  finally {32    await helper.disconnect();33    await helper.disconnectWeb3();34    silentConsole.disable();35  }36}37  38export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {39  let i: any = it;40  if (opts.only) i = i.only;41  else if (opts.skip) i = i.skip;42  i(name, async () => {43    await usingEthPlaygrounds(async (helper, privateKey) => {44      await cb({helper, privateKey});45    });46  });47}48itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});49itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
after · tests/src/eth/util/playgrounds/index.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15chai.use(chaiAsPromised);16export const expect = chai.expect;1718export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {19  const silentConsole = new SilentConsole();20  silentConsole.enable();2122  const helper = new EthUniqueHelper(new SilentLogger());2324  try {25    await helper.connect(config.substrateUrl);26    await helper.connectWeb3(config.substrateUrl);27    const ss58Format = helper.chain.getChainProperties().ss58Format;28    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);29    await code(helper, privateKey);30  }31  finally {32    await helper.disconnect();33    await helper.disconnectWeb3();34    silentConsole.disable();35  }36};37  38export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {39  let i: any = it;40  if (opts.only) i = i.only;41  else if (opts.skip) i = i.skip;42  i(name, async () => {43    await usingEthPlaygrounds(async (helper, privateKey) => {44      await cb({helper, privateKey});45    });46  });47}48itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});49itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
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',
     );
   }