difftreelog
ES lint issues fixed
in: master
58 files changed
tests/src/addToContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractWhiteList.test.ts
+++ b/tests/src/addToContractWhiteList.test.ts
@@ -3,25 +3,25 @@
// file 'LICENSE', which is part of this source code package.
//
-import chai from "chai";
+import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import privateKey from "./substrate/privateKey";
+import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
import {
- deployFlipper
-} from "./util/contracthelpers";
+ deployFlipper,
+} from './util/contracthelpers';
import {
- getGenericResult, normalizeAccountId
-} from "./util/helpers"
+ getGenericResult,
+} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Integration Test addToContractWhiteList', () => {
- it(`Add an address to a contract white list`, async () => {
+ it('Add an address to a contract white list', async () => {
await usingApi(async api => {
- const bob = privateKey("//Bob");
+ const bob = privateKey('//Bob');
const [contract, deployer] = await deployFlipper(api);
const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
@@ -35,9 +35,9 @@
});
});
- it(`Adding same address to white list repeatedly should not produce errors`, async () => {
+ it('Adding same address to white list repeatedly should not produce errors', async () => {
await usingApi(async api => {
- const bob = privateKey("//Bob");
+ const bob = privateKey('//Bob');
const [contract, deployer] = await deployFlipper(api);
const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
@@ -58,11 +58,11 @@
describe('Negative Integration Test addToContractWhiteList', () => {
- it(`Add an address to a white list of a non-contract`, async () => {
+ it('Add an address to a white list of a non-contract', async () => {
await usingApi(async api => {
- const alice = privateKey("//Bob");
- const bob = privateKey("//Bob");
- const charlieGuineaPig = privateKey("//Charlie");
+ const alice = privateKey('//Bob');
+ const bob = privateKey('//Bob');
+ const charlieGuineaPig = privateKey('//Charlie');
const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();
const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);
@@ -74,10 +74,10 @@
});
});
- it(`Add to a contract white list using a non-owner address`, async () => {
+ it('Add to a contract white list using a non-owner address', async () => {
await usingApi(async api => {
- const bob = privateKey("//Bob");
- const [contract, deployer] = await deployFlipper(api);
+ const bob = privateKey('//Bob');
+ const [contract] = await deployFlipper(api);
const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();
const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -1,87 +1,87 @@
-//
-// 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, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import {
- addToWhiteListExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- destroyCollectionExpectSuccess,
- enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
- normalizeAccountId,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-
-describe('Integration Test ext. addToWhiteList()', () => {
-
- before(async () => {
- await usingApi(async (api) => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- });
- });
-
- it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- });
-
- it('Whitelisted minting: list restrictions', async () => {
- const collectionId = await createCollectionExpectSuccess();
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
- });
-});
-
-describe('Negative Integration Test ext. addToWhiteList()', () => {
-
- it('White list an address in the collection that does not exist', async () => {
- await usingApi(async (api) => {
- // tslint:disable-next-line: no-bitwise
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
- const Bob = privateKey('//Bob');
-
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
- });
- });
-
- it('White list an address in the collection that was destroyed', async () => {
- await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Bob = privateKey('//Bob');
- // tslint:disable-next-line: no-bitwise
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
- });
- });
-
- it('White list an address in the collection that does not have white list access enabled', async () => {
- await usingApi(async (api) => {
- const Alice = privateKey('//Alice');
- const Ferdie = privateKey('//Ferdie');
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
- });
- });
-
-});
+//
+// 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, { submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {
+ addToWhiteListExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enablePublicMintingExpectSuccess,
+ enableWhiteListExpectSuccess,
+ normalizeAccountId,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+
+describe('Integration Test ext. addToWhiteList()', () => {
+
+ before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ });
+ });
+
+ it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ });
+
+ it('Whitelisted minting: list restrictions', async () => {
+ const collectionId = await createCollectionExpectSuccess();
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ });
+});
+
+describe('Negative Integration Test ext. addToWhiteList()', () => {
+
+ it('White list an address in the collection that does not exist', async () => {
+ await usingApi(async (api) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const Bob = privateKey('//Bob');
+
+ const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('White list an address in the collection that was destroyed', async () => {
+ await usingApi(async (api) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId);
+ const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(Bob.address));
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('White list an address in the collection that does not have white list access enabled', async () => {
+ await usingApi(async (api) => {
+ const Alice = privateKey('//Alice');
+ const Ferdie = privateKey('//Ferdie');
+ const collectionId = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Ferdie.address), 'NFT');
+ await expect(submitTransactionExpectFailAsync(Ferdie, tx)).to.be.rejected;
+ });
+ });
+
+});
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -82,7 +82,7 @@
let Charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
Charlie = privateKey('//Charlie');
tests/src/block-production.test.tsdiffbeforeafterboth--- a/tests/src/block-production.test.ts
+++ b/tests/src/block-production.test.ts
@@ -3,14 +3,15 @@
// file 'LICENSE', which is part of this source code package.
//
-import usingApi from "./substrate/substrate-api";
-import { expect } from "chai";
-import { ApiPromise } from "@polkadot/api";
+import usingApi from './substrate/substrate-api';
+import { expect } from 'chai';
+import { ApiPromise } from '@polkadot/api';
const BlockTimeMs = 12000;
const ToleranceMs = 1000;
-async function getBlocks(api: ApiPromise): Promise<number[]> {
+/* eslint no-async-promise-executor: "off" */
+function getBlocks(api: ApiPromise): Promise<number[]> {
return new Promise<number[]>(async (resolve, reject) => {
const blockNumbers: number[] = [];
setTimeout(() => reject('Block production test failed due to timeout.'), BlockTimeMs + ToleranceMs);
@@ -27,7 +28,7 @@
describe('Block Production smoke test', () => {
it('Node produces new blocks', async () => {
await usingApi(async (api) => {
- let blocks: number[] | undefined = await getBlocks(api);
+ const blocks: number[] | undefined = await getBlocks(api);
expect(blocks[0]).to.be.lessThan(blocks[1]);
});
});
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -4,16 +4,15 @@
//
import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
createItemExpectSuccess,
getGenericResult,
destroyCollectionExpectSuccess,
- normalizeAccountId
+ normalizeAccountId,
} from './util/helpers';
-import { nullPublicKey } from "./accounts";
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -25,10 +24,10 @@
describe('integration test: ext. burnItem():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
});
});
@@ -139,10 +138,10 @@
describe('Negative integration test: ext. burnItem():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
});
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -6,8 +6,8 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, createCollectionExpectFailure, normalizeAccountId } from "./util/helpers";
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import { createCollectionExpectSuccess, normalizeAccountId } from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -32,7 +32,7 @@
});
describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
- it(`Not owner can't change owner.`, async () => {
+ it('Not owner can\'t change owner.', async () => {
await usingApi(async api => {
const collectionId = await createCollectionExpectSuccess();
const alice = privateKey('//Alice');
@@ -48,7 +48,7 @@
await createCollectionExpectSuccess();
});
});
- it(`Can't change owner of not existing collection.`, async () => {
+ it('Can\'t change owner of not existing collection.', async () => {
await usingApi(async api => {
const collectionId = (1<<32) - 1;
const alice = privateKey('//Alice');
tests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits7import { ApiPromise } from '@polkadot/api';8import { IKeyringPair } from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import privateKey from '../substrate/privateKey';12import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';13import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';1415chai.use(chaiAsPromised);16const expect = chai.expect;1718describe('Create Item event ', () => {19 let Alice: IKeyringPair;20 const checkSection = 'ItemCreated';21 const checkTreasury = 'Deposit';22 const checkSystem = 'ExtrinsicSuccess';23 before(async () => {24 await usingApi(async () => {25 Alice = privateKey('//Alice');26 });27 });28 it('Check event from createItem(): ', async () => {29 await usingApi(async (api: ApiPromise) => {30 const collectionID = await createCollectionExpectSuccess();31 const createItem = api.tx.nft.createItem(collectionID, Alice.address, 'NFT');32 const events = await submitTransactionAsync(Alice, createItem);33 const msg = JSON.stringify(nftEventMessage(events));34 expect(msg).to.be.contain(checkSection);35 expect(msg).to.be.contain(checkTreasury);36 expect(msg).to.be.contain(checkSystem);37 });38 });39});401//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits7import { ApiPromise } from '@polkadot/api';8import { IKeyringPair } from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import privateKey from '../substrate/privateKey';12import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';13import { createCollectionExpectSuccess, nftEventMessage } from '../util/helpers';1415chai.use(chaiAsPromised);16const expect = chai.expect;1718describe('Create Item event ', () => {19 let Alice: IKeyringPair;20 const checkSection = 'ItemCreated';21 const checkTreasury = 'Deposit';22 const checkSystem = 'ExtrinsicSuccess';23 before(async () => {24 await usingApi(async () => {25 Alice = privateKey('//Alice');26 });27 });28 it('Check event from createItem(): ', async () => {29 await usingApi(async (api: ApiPromise) => {30 const collectionID = await createCollectionExpectSuccess();31 const createItem = api.tx.nft.createItem(collectionID, Alice.address, 'NFT');32 const events = await submitTransactionAsync(Alice, createItem);33 const msg = JSON.stringify(nftEventMessage(events));34 expect(msg).to.be.contain(checkSection);35 expect(msg).to.be.contain(checkTreasury);36 expect(msg).to.be.contain(checkSystem);37 });38 });39});40tests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createMultipleItemsEvent.test.ts
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -10,7 +10,7 @@
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+import { createCollectionExpectSuccess, nftEventMessage } from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
tests/src/collision-tests/admVsOwnerChanges.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerChanges.test.ts
+++ b/tests/src/collision-tests/admVsOwnerChanges.test.ts
@@ -1,55 +1,50 @@
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey, bobsPublicKey } from '../accounts';
-import getBalance from '../substrate/get-balance';
-import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import {
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- setCollectionSponsorExpectSuccess,
-} from '../util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-
-before(async () => {
- await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- });
-});
-
-describe('Admin vs Owner changes token: ', () => {
- // tslint:disable-next-line: max-line-length
- it('The collection admin changes the owner of the token and in the same block the current owner transfers the token to another address ', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
- await submitTransactionAsync(Alice, changeAdminTxBob);
- const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
- await submitTransactionAsync(Bob, changeAdminTxFerdie);
- const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
- //
- const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);
- const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);
- const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
- await Promise.all
- ([
- changeOwner.signAndSend(Alice),
- approve.signAndSend(Bob),
- sendItem.signAndSend(Ferdie),
- ]);
- const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
- expect(itemBefore.Owner).not.to.be.eq(Bob.address);
- await timeoutPromise(20000);
- });
- });
-});
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Ferdie = privateKey('//Ferdie');
+ });
+});
+
+describe('Admin vs Owner changes token: ', () => {
+ // tslint:disable-next-line: max-line-length
+ it('The collection admin changes the owner of the token and in the same block the current owner transfers the token to another address ', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, changeAdminTxBob);
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ const changeAdminTxFerdie = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
+ await submitTransactionAsync(Bob, changeAdminTxFerdie);
+ const itemId = await createItemExpectSuccess(Ferdie, collectionId, 'NFT');
+ //
+ const changeOwner = api.tx.nft.transferFrom(Ferdie.address, Bob.address, collectionId, itemId, 1);
+ const approve = api.tx.nft.approve(Bob.address, collectionId, itemId, 1);
+ const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
+ await Promise.all([
+ changeOwner.signAndSend(Alice),
+ approve.signAndSend(Bob),
+ sendItem.signAndSend(Ferdie),
+ ]);
+ const itemBefore: any = await api.query.nft.nftItemList(collectionId, itemId);
+ expect(itemBefore.Owner).not.to.be.eq(Bob.address);
+ await timeoutPromise(20000);
+ });
+ });
+});
tests/src/collision-tests/admVsOwnerData.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerData.test.ts
+++ b/tests/src/collision-tests/admVsOwnerData.test.ts
@@ -1,54 +1,47 @@
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey, bobsPublicKey } from '../accounts';
-import getBalance from '../substrate/get-balance';
-import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import {
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- setCollectionSponsorExpectSuccess,
-} from '../util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-
-before(async () => {
- await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- });
-});
-
-describe('Admin vs Owner changes the data in the token: ', () => {
- it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => {
- await usingApi(async (api) => {
- const AliceData = 1;
- const BobData = 2;
- const collectionId = await createCollectionExpectSuccess();
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
- await submitTransactionAsync(Alice, changeAdminTx);
- const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
- //
- // tslint:disable-next-line: max-line-length
- const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, AliceData.toString());
- // tslint:disable-next-line: max-line-length
- const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, BobData.toString());
- await Promise.all
- ([
- AliceTx.signAndSend(Alice),
- BobTx.signAndSend(Bob),
- ]);
- const item: any = await api.query.nft.nftItemList(collectionId, itemId);
- expect(item.VariableData).not.to.be.eq(null); // Pseudo-random selection of one of two values
- await timeoutPromise(20000);
- });
- });
-});
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ });
+});
+
+describe('Admin vs Owner changes the data in the token: ', () => {
+ it('The collection admin changes the data in the token and in the same block the token owner also changes the data in it ', async () => {
+ await usingApi(async (api) => {
+ const AliceData = 1;
+ const BobData = 2;
+ const collectionId = await createCollectionExpectSuccess();
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, changeAdminTx);
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+ //
+ // tslint:disable-next-line: max-line-length
+ const AliceTx = api.tx.nft.setVariableMetaData(collectionId, itemId, AliceData.toString());
+ // tslint:disable-next-line: max-line-length
+ const BobTx = api.tx.nft.setVariableMetaData(collectionId, itemId, BobData.toString());
+ await Promise.all([
+ AliceTx.signAndSend(Alice),
+ BobTx.signAndSend(Bob),
+ ]);
+ const item: any = await api.query.nft.nftItemList(collectionId, itemId);
+ expect(item.VariableData).not.to.be.eq(null); // Pseudo-random selection of one of two values
+ await timeoutPromise(20000);
+ });
+ });
+});
tests/src/collision-tests/admVsOwnerTake.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/admVsOwnerTake.test.ts
+++ b/tests/src/collision-tests/admVsOwnerTake.test.ts
@@ -1,54 +1,49 @@
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey, bobsPublicKey } from '../accounts';
-import getBalance from '../substrate/get-balance';
-import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import {
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- setCollectionSponsorExpectSuccess,
-} from '../util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-
-before(async () => {
- await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- });
-});
-
-describe('Admin vs Owner take token: ', () => {
- // tslint:disable-next-line: max-line-length
- it('The collection admin burns the token and in the same block the token owner performs a transaction on it ', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
- await submitTransactionAsync(Alice, changeAdminTx);
- const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
- //
- const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1);
- const burnItem = api.tx.nft.burnItem(collectionId, itemId, 1);
- await Promise.all
- ([
- sendItem.signAndSend(Bob),
- burnItem.signAndSend(Alice),
- ]);
- await timeoutPromise(10000);
- let itemBurn: boolean = false;
- itemBurn = (await (api.query.nft.nftItemList(collectionId, itemId))).toJSON() as boolean;
- // tslint:disable-next-line: no-unused-expression
- expect(itemBurn).to.be.null;
- await timeoutPromise(20000);
- });
- });
-});
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ Ferdie = privateKey('//Ferdie');
+ });
+});
+
+describe('Admin vs Owner take token: ', () => {
+ // tslint:disable-next-line: max-line-length
+ it('The collection admin burns the token and in the same block the token owner performs a transaction on it ', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, changeAdminTx);
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+ //
+ const sendItem = api.tx.nft.transfer(Ferdie.address, collectionId, itemId, 1);
+ const burnItem = api.tx.nft.burnItem(collectionId, itemId, 1);
+ await Promise.all([
+ sendItem.signAndSend(Bob),
+ burnItem.signAndSend(Alice),
+ ]);
+ await timeoutPromise(10000);
+ let itemBurn = false;
+ itemBurn = (await (api.query.nft.nftItemList(collectionId, itemId))).toJSON() as boolean;
+ // tslint:disable-next-line: no-unused-expression
+ expect(itemBurn).to.be.null;
+ await timeoutPromise(20000);
+ });
+ });
+});
tests/src/collision-tests/adminDestroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminDestroyCollection.test.ts
+++ b/tests/src/collision-tests/adminDestroyCollection.test.ts
@@ -1,35 +1,23 @@
import { IKeyringPair } from '@polkadot/types/types';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
import {
createCollectionExpectSuccess,
} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- Owner: number[];
- ConstData: number[];
- VariableData: number[];
-}
let Alice: IKeyringPair;
let Bob: IKeyringPair;
let Ferdie: IKeyringPair;
-let Charlie: IKeyringPair;
-let Eve: IKeyringPair;
-let Dave: IKeyringPair;
before(async () => {
await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
Ferdie = privateKey('//Ferdie');
- Charlie = privateKey('//Charlie');
- Eve = privateKey('//Eve');
- Dave = privateKey('//Dave');
});
});
@@ -45,13 +33,12 @@
//
const addWhitelistAdm = api.tx.nft.addToWhiteList(collectionId, Ferdie.address);
const destroyCollection = api.tx.nft.destroyCollection(collectionId);
- await Promise.all
- ([
+ await Promise.all([
addWhitelistAdm.signAndSend(Bob),
destroyCollection.signAndSend(Alice),
]);
await timeoutPromise(10000);
- let whiteList: boolean = false;
+ let whiteList = false;
whiteList = (await api.query.nft.whiteList(collectionId, Ferdie.address)).toJSON() as boolean;
// tslint:disable-next-line: no-unused-expression
expect(whiteList).to.be.false;
tests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminLimitsOff.test.ts
+++ b/tests/src/collision-tests/adminLimitsOff.test.ts
@@ -10,11 +10,6 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- Owner: number[];
- ConstData: number[];
- VariableData: number[];
-}
let Alice: IKeyringPair;
let Bob: IKeyringPair;
let Ferdie: IKeyringPair;
@@ -51,11 +46,9 @@
await submitTransactionAsync(Alice, changeAdminTx3);
const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- //
const addAdmOne = api.tx.nft.addCollectionAdmin(collectionId, Ferdie.address);
const addAdmTwo = api.tx.nft.addCollectionAdmin(collectionId, Charlie.address);
- await Promise.all
- ([
+ await Promise.all([
addAdmOne.signAndSend(Bob),
addAdmTwo.signAndSend(Alice),
]);
tests/src/collision-tests/adminRightsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminRightsOff.test.ts
+++ b/tests/src/collision-tests/adminRightsOff.test.ts
@@ -3,33 +3,20 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
import {
createCollectionExpectSuccess,
} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- Owner: number[];
- ConstData: number[];
- VariableData: number[];
-}
let Alice: IKeyringPair;
let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-let Charlie: IKeyringPair;
-let Eve: IKeyringPair;
-let Dave: IKeyringPair;
before(async () => {
await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- Charlie = privateKey('//Charlie');
- Eve = privateKey('//Eve');
- Dave = privateKey('//Dave');
});
});
@@ -42,12 +29,10 @@
await submitTransactionAsync(Alice, changeAdminTx);
const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
await timeoutPromise(10000);
- //
const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
const addItemAdm = api.tx.nft.createMultipleItems(collectionId, Bob.address, args);
const removeAdm = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
- await Promise.all
- ([
+ await Promise.all([
addItemAdm.signAndSend(Bob),
removeAdm.signAndSend(Alice),
]);
tests/src/collision-tests/setSponsorNewOwner.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/setSponsorNewOwner.test.ts
+++ b/tests/src/collision-tests/setSponsorNewOwner.test.ts
@@ -1,20 +1,14 @@
import { IKeyringPair } from '@polkadot/types/types';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import usingApi from '../substrate/substrate-api';
import {
- createCollectionExpectSuccess, createItemExpectSuccess, setCollectionSponsorExpectSuccess,
+ createCollectionExpectSuccess, setCollectionSponsorExpectSuccess,
} from '../util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- Owner: number[];
- ConstData: number[];
- VariableData: number[];
-}
let Alice: IKeyringPair;
let Bob: IKeyringPair;
let Ferdie: IKeyringPair;
@@ -35,11 +29,9 @@
await setCollectionSponsorExpectSuccess(collectionId, Bob.address);
const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
await timeoutPromise(10000);
- //
const confirmSponsorship = api.tx.nft.confirmSponsorship(collectionId);
const changeCollectionOwner = api.tx.nft.changeCollectionOwner(collectionId, Ferdie.address);
- await Promise.all
- ([
+ await Promise.all([
confirmSponsorship.signAndSend(Bob),
changeCollectionOwner.signAndSend(Alice),
]);
tests/src/collision-tests/sponsorPayments.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/sponsorPayments.test.ts
+++ b/tests/src/collision-tests/sponsorPayments.test.ts
@@ -1,58 +1,54 @@
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey, bobsPublicKey } from '../accounts';
-import getBalance from '../substrate/get-balance';
-import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import {
- confirmSponsorshipExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- setCollectionSponsorExpectSuccess,
-} from '../util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-
-before(async () => {
- await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- });
-});
-
-describe('Payment of commission if one block: ', () => {
- // tslint:disable-next-line: max-line-length
- it('Payment of commission if one block contains transactions for payment from the sponsor\'s balance and his (sponsor\'s) exclusion from the collection ', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
- await submitTransactionAsync(Alice, changeAdminTxBob);
- const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
- await setCollectionSponsorExpectSuccess(collectionId, Bob.address);
- await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- //
- const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
- const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
- const revokeSponsor = api.tx.nft.removeCollectionSponsor(collectionId);
- await Promise.all
- ([
- sendItem.signAndSend(Bob),
- revokeSponsor.signAndSend(Alice),
- ]);
- const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
- // tslint:disable-next-line:no-unused-expression
- expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;
- await timeoutPromise(20000);
- });
- });
-});
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { alicesPublicKey, bobsPublicKey } from '../accounts';
+import getBalance from '../substrate/get-balance';
+import privateKey from '../substrate/privateKey';
+import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
+import {
+ confirmSponsorshipExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ setCollectionSponsorExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ });
+});
+
+describe('Payment of commission if one block: ', () => {
+ // tslint:disable-next-line: max-line-length
+ it('Payment of commission if one block contains transactions for payment from the sponsor\'s balance and his (sponsor\'s) exclusion from the collection ', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const changeAdminTxBob = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, changeAdminTxBob);
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ const itemId = await createItemExpectSuccess(Bob, collectionId, 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, Bob.address);
+ await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+
+ const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+ const sendItem = api.tx.nft.transfer(Alice.address, collectionId, itemId, 1);
+ const revokeSponsor = api.tx.nft.removeCollectionSponsor(collectionId);
+ await Promise.all([
+ sendItem.signAndSend(Bob),
+ revokeSponsor.signAndSend(Alice),
+ ]);
+ const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+ // tslint:disable-next-line:no-unused-expression
+ expect(alicesBalanceAfter === alicesBalanceBefore).to.be.true;
+ // tslint:disable-next-line:no-unused-expression
+ expect(bobsBalanceAfter === bobsBalanceBefore).to.be.true;
+ await timeoutPromise(20000);
+ });
+ });
+});
tests/src/collision-tests/tokenLimitsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/tokenLimitsOff.test.ts
+++ b/tests/src/collision-tests/tokenLimitsOff.test.ts
@@ -13,11 +13,6 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-interface ITokenDataType {
- Owner: number[];
- ConstData: number[];
- VariableData: number[];
-}
let Alice: IKeyringPair;
let Bob: IKeyringPair;
let Ferdie: IKeyringPair;
@@ -63,14 +58,13 @@
expect(subTxTesult.success).to.be.true;
const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
await timeoutPromise(10000);
- //
+
const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
const mintItemOne = api.tx.nft
.createMultipleItems(collectionId, Ferdie.address, args);
const mintItemTwo = api.tx.nft
.createMultipleItems(collectionId, Bob.address, args);
- await Promise.all
- ([
+ await Promise.all([
mintItemOne.signAndSend(Ferdie),
mintItemTwo.signAndSend(Bob),
]);
tests/src/collision-tests/turnsOffMinting.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/turnsOffMinting.test.ts
+++ b/tests/src/collision-tests/turnsOffMinting.test.ts
@@ -1,50 +1,46 @@
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
-import usingApi, { submitTransactionAsync } from '../substrate/substrate-api';
-import waitNewBlocks from '../substrate/wait-new-blocks';
-import {
- addToWhiteListExpectSuccess,
- createCollectionExpectSuccess,
- setMintPermissionExpectSuccess,
-} from '../util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-let Ferdie: IKeyringPair;
-
-before(async () => {
- await usingApi(async () => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- Ferdie = privateKey('//Ferdie');
- });
-});
-
-describe('Turns off minting mode: ', () => {
- // tslint:disable-next-line: max-line-length
- it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
- await setMintPermissionExpectSuccess(Alice, collectionId, true);
- await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
- //
- const mintItem = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
- const offMinting = api.tx.nft.setMintPermission(collectionId, false);
- await Promise.all
- ([
- mintItem.signAndSend(Ferdie),
- offMinting.signAndSend(Alice),
- ]);
- let itemList: boolean = false;
- itemList = (await (api.query.nft.nftItemList(collectionId, mintItem))).toJSON() as boolean;
- // tslint:disable-next-line: no-unused-expression
- expect(itemList).to.be.null;
- await timeoutPromise(20000);
- });
- });
-});
+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 {
+ addToWhiteListExpectSuccess,
+ createCollectionExpectSuccess,
+ setMintPermissionExpectSuccess,
+} from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+let Alice: IKeyringPair;
+let Ferdie: IKeyringPair;
+
+before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Ferdie = privateKey('//Ferdie');
+ });
+});
+
+describe('Turns off minting mode: ', () => {
+ // tslint:disable-next-line: max-line-length
+ it('The collection owner turns off minting mode and there are minting transactions in the same block ', async () => {
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const timeoutPromise = (timeout: number) => new Promise((resolve) => setTimeout(resolve, timeout));
+ await setMintPermissionExpectSuccess(Alice, collectionId, true);
+ await addToWhiteListExpectSuccess(Alice, collectionId, Ferdie.address);
+
+ const mintItem = api.tx.nft.createItem(collectionId, Ferdie.address, 'NFT');
+ const offMinting = api.tx.nft.setMintPermission(collectionId, false);
+ await Promise.all([
+ mintItem.signAndSend(Ferdie),
+ offMinting.signAndSend(Alice),
+ ]);
+ let itemList = false;
+ itemList = (await (api.query.nft.nftItemList(collectionId, mintItem))).toJSON() as boolean;
+ // tslint:disable-next-line: no-unused-expression
+ expect(itemList).to.be.null;
+ await timeoutPromise(20000);
+ });
+ });
+});
tests/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:9844',
+};
export default config;
\ No newline at end of file
tests/src/config_docker.tsdiffbeforeafterboth--- a/tests/src/config_docker.ts
+++ b/tests/src/config_docker.ts
@@ -6,7 +6,7 @@
import process from 'process';
const config = {
- substrateUrl: process.env.substrateUrl || 'ws://172.17.0.1:9944'
-}
+ substrateUrl: process.env.substrateUrl || 'ws://172.17.0.1:9944',
+};
export default config;
\ No newline at end of file
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -5,12 +5,11 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
setCollectionSponsorExpectSuccess,
destroyCollectionExpectSuccess,
- setCollectionSponsorExpectFailure,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
createItemExpectSuccess,
@@ -20,10 +19,9 @@
enablePublicMintingExpectSuccess,
addToWhiteListExpectSuccess,
normalizeAccountId,
-} from "./util/helpers";
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
-import type { AccountId } from '@polkadot/types/interfaces';
+} from './util/helpers';
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
import { BigNumber } from 'bignumber.js';
chai.use(chaiAsPromised);
@@ -36,11 +34,11 @@
describe('integration test: ext. confirmSponsorship():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
- charlie = keyring.addFromUri(`//Charlie`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
+ charlie = keyring.addFromUri('//Charlie');
});
});
@@ -163,7 +161,7 @@
await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);
// Mint token using unused address as signer
- const tokenId = await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
+ await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -195,7 +193,7 @@
const badTransaction = async function () {
await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
- await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
+ await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
// Try again after Zero gets some balance - now it should succeed
@@ -228,11 +226,7 @@
const result1 = getGenericResult(events1);
const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
-
- const badTransaction = async function () {
- await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
- };
-
+ await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
// Try again after Zero gets some balance - now it should succeed
@@ -271,7 +265,7 @@
const badTransaction = async function () {
await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
- await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
+ await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
// Try again after Zero gets some balance - now it should succeed
@@ -317,7 +311,7 @@
const badTransaction = async function () {
await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
};
- await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
+ await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
console.error = consoleError;
console.log = consoleLog;
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
@@ -335,19 +329,19 @@
describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
- charlie = keyring.addFromUri(`//Charlie`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
+ charlie = keyring.addFromUri('//Charlie');
});
});
it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {
// Find the collection that never existed
- const collectionId = 0;
+ let collectionId = 0;
await usingApi(async (api) => {
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
});
await confirmSponsorshipExpectFailure(collectionId, '//Bob');
tests/src/connection.test.tsdiffbeforeafterboth--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import usingApi from "./substrate/substrate-api";
+import usingApi from './substrate/substrate-api';
import { WsProvider } from '@polkadot/api';
import * as chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -29,7 +29,7 @@
const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');
await expect((async () => {
await usingApi(async api => {
- const health = await api.rpc.system.health();
+ await api.rpc.system.health();
}, { provider: neverConnectProvider });
})()).to.be.eventually.rejected;
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -3,17 +3,17 @@
// file 'LICENSE', which is part of this source code package.
//
-import chai from "chai";
+import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import fs from "fs";
-import { Abi, ContractPromise as Contract } from "@polkadot/api-contract";
-import privateKey from "./substrate/privateKey";
+import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import fs from 'fs';
+import { Abi, ContractPromise as Contract } from '@polkadot/api-contract';
+import privateKey from './substrate/privateKey';
import {
deployFlipper,
getFlipValue,
deployTransferContract,
-} from "./util/contracthelpers";
+} from './util/contracthelpers';
import {
addToWhiteListExpectSuccess,
@@ -25,8 +25,8 @@
getGenericResult,
normalizeAccountId,
isWhitelisted,
- transferFromExpectSuccess
-} from "./util/helpers";
+ transferFromExpectSuccess,
+} from './util/helpers';
chai.use(chaiAsPromised);
@@ -37,12 +37,12 @@
const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6';
describe('Contracts', () => {
- it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => {
+ 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);
const initialGetResponse = await getFlipValue(contract, deployer);
- const bob = privateKey("//Bob");
+ const bob = privateKey('//Bob');
const flip = contract.tx.flip(value, gasLimit);
await submitTransactionAsync(bob, flip);
@@ -65,13 +65,13 @@
describe.only('Chain extensions', () => {
it('Transfer CE', async () => {
await usingApi(async api => {
- const alice = privateKey("//Alice");
- const bob = privateKey("//Bob");
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
// Prep work
const collectionId = await createCollectionExpectSuccess();
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
@@ -96,7 +96,7 @@
const bob = privateKey('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
await enablePublicMintingExpectSuccess(alice, collectionId);
await enableWhiteListExpectSuccess(alice, collectionId);
await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
@@ -124,7 +124,7 @@
const bob = privateKey('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
await enablePublicMintingExpectSuccess(alice, collectionId);
await enableWhiteListExpectSuccess(alice, collectionId);
await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
@@ -133,7 +133,7 @@
const transferTx = contract.tx.createMultipleItems(value, gasLimit, bob.address, collectionId, [
{ Nft: { const_data: '0x010203', variable_data: '0x020304' } },
{ Nft: { const_data: '0x010204', variable_data: '0x020305' } },
- { Nft: { const_data: '0x010205', variable_data: '0x020306' } }
+ { Nft: { const_data: '0x010205', variable_data: '0x020306' } },
]);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
@@ -169,7 +169,7 @@
const charlie = privateKey('//Charlie');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);
@@ -188,7 +188,7 @@
const charlie = privateKey('//Charlie');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);
@@ -197,7 +197,7 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap()
+ const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
expect(token.Owner.toString()).to.be.equal(charlie.address);
});
});
@@ -207,7 +207,7 @@
const alice = privateKey('//Alice');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
const transferTx = contract.tx.setVariableMetaData(value, gasLimit, collectionId, tokenId, '0x121314');
@@ -215,7 +215,7 @@
const result = getGenericResult(events);
expect(result.success).to.be.true;
- const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap()
+ const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
expect(token.VariableData.toString()).to.be.equal('0x121314');
});
});
@@ -226,7 +226,7 @@
const bob = privateKey('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract, deployer] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api);
const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -1,39 +1,39 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-import { default as usingApi } from './substrate/substrate-api';
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
-import {
- createCollectionExpectSuccess,
- createItemExpectSuccess
-} from './util/helpers';
-
-let alice: IKeyringPair;
-
-describe('integration test: ext. createItem():', () => {
- before(async () => {
- await usingApi(async (api) => {
- const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- });
- });
-
- it('Create new item in NFT collection', async () => {
- const createMode = 'NFT';
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
- });
- it('Create new item in Fungible collection', async () => {
- const createMode = 'Fungible';
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
- });
- it('Create new item in ReFungible collection', async () => {
- const createMode = 'ReFungible';
- const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
- await createItemExpectSuccess(alice, newCollectionID, createMode);
- });
-});
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { default as usingApi } from './substrate/substrate-api';
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+} from './util/helpers';
+
+let alice: IKeyringPair;
+
+describe('integration test: ext. createItem():', () => {
+ before(async () => {
+ await usingApi(async () => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri('//Alice');
+ });
+ });
+
+ it('Create new item in NFT collection', async () => {
+ const createMode = 'NFT';
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
+ await createItemExpectSuccess(alice, newCollectionID, createMode);
+ });
+ it('Create new item in Fungible collection', async () => {
+ const createMode = 'Fungible';
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
+ await createItemExpectSuccess(alice, newCollectionID, createMode);
+ });
+ it('Create new item in ReFungible collection', async () => {
+ const createMode = 'ReFungible';
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
+ await createItemExpectSuccess(alice, newCollectionID, createMode);
+ });
+});
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -5,16 +5,16 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import { alicesPublicKey, bobsPublicKey } from "./accounts";
-import privateKey from "./substrate/privateKey";
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import { alicesPublicKey, bobsPublicKey } from './accounts';
+import privateKey from './substrate/privateKey';
import { BigNumber } from 'bignumber.js';
import { IKeyringPair } from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
createItemExpectSuccess,
getGenericResult,
- transferExpectSuccess
+ transferExpectSuccess,
} from './util/helpers';
import { default as waitNewBlocks } from './substrate/wait-new-blocks';
@@ -23,7 +23,7 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-const Treasury = "5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z";
+const Treasury = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
const saneMinimumFee = 0.05;
const saneMaximumFee = 0.5;
const createCollectionDeposit = 100;
@@ -33,8 +33,9 @@
// Skip the inflation block pauses if the block is close to inflation block
// until the inflation happens
+/*eslint no-async-promise-executor: "off"*/
function skipInflationBlock(api: ApiPromise): Promise<void> {
- const promise = new Promise<void>(async (resolve, reject) => {
+ const promise = new Promise<void>(async (resolve) => {
const blockInterval = parseInt((await api.consts.inflation.inflationBlockInterval).toString());
const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
const currentBlock = parseInt(head.number.toString());
@@ -52,7 +53,7 @@
describe('integration test: Fees must be credited to Treasury:', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -7,8 +7,8 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
-import { default as usingApi } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from "./util/helpers";
+import { default as usingApi } from './substrate/substrate-api';
+import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from './util/helpers';
chai.use(chaiAsPromised);
@@ -31,7 +31,7 @@
let alice: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
});
});
tests/src/enableContractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/enableContractSponsoring.test.ts
+++ b/tests/src/enableContractSponsoring.test.ts
@@ -81,7 +81,7 @@
it('fails when called by non-owning user', async () => {
await usingApi(async (api) => {
- const [flipper, _] = await deployFlipper(api);
+ const [flipper] = await deployFlipper(api);
await enableContractSponsoringExpectFailure(alice, flipper.address, true);
});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -1,289 +1,294 @@
-import privateKey from "../substrate/privateKey";
-import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from "../util/helpers";
-import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from "./util/helpers"
+//
+// 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 { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
+import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
import fungibleAbi from './fungibleAbi.json';
-import { expect } from "chai";
+import { expect } from 'chai';
describe('Information getting', () => {
- itWeb3('totalSupply', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
+ itWeb3('totalSupply', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
- const totalSupply = await contract.methods.totalSupply().call();
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ const totalSupply = await contract.methods.totalSupply().call();
+
+ // FIXME: always equals to 0, because this method is not implemented
+ expect(totalSupply).to.equal('0');
+ });
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ itWeb3('balanceOf', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'Fungible', decimalPoints: 0 },
});
+ const alice = privateKey('//Alice');
- itWeb3('balanceOf', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
+ const caller = createEthAccount(web3);
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
- const caller = createEthAccount(web3);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ const balance = await contract.methods.balanceOf(caller).call();
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
- const balance = await contract.methods.balanceOf(caller).call();
-
- expect(balance).to.equal('200');
- });
+ expect(balance).to.equal('200');
+ });
});
describe('Plain calls', () => {
- itWeb3('Can perform approve()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
+ itWeb3('Can perform approve()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
- const spender = createEthAccount(web3);
+ const spender = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
+
+ {
+ const result = await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ const events = normalizeEvents(result.events);
+ expect(events).to.be.deep.equal([
{
- const result = await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
- const events = normalizeEvents(result.events);
+ address,
+ event: 'Approval',
+ args: {
+ owner,
+ spender,
+ value: '100',
+ },
+ },
+ ]);
+ }
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '100',
- }
- }
- ]);
- }
+ {
+ const allowance = await contract.methods.allowance(owner, spender).call();
+ expect(+allowance).to.equal(100);
+ }
+ });
- {
- const allowance = await contract.methods.allowance(owner, spender).call();
- expect(+allowance).to.equal(100);
- }
+ itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'Fungible', decimalPoints: 0 },
});
+ const alice = privateKey('//Alice');
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
- const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender, 999999999999999);
+ const spender = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, spender, 999999999999999);
- const receiver = createEthAccount(web3);
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
- await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ {
+ const result = await contract.methods.transferFrom(owner, receiver, 49).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
+ const events = normalizeEvents(result.events);
+ expect(events).to.be.deep.equal([
{
- const result = await contract.methods.transferFrom(owner, receiver, 49).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '49',
- }
- },
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '51',
- }
- }
- ]);
- }
-
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: receiver,
+ value: '49',
+ },
+ },
{
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(49);
- }
+ address,
+ event: 'Approval',
+ args: {
+ owner,
+ spender,
+ value: '51',
+ },
+ },
+ ]);
+ }
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(151);
- }
- });
+ {
+ const balance = await contract.methods.balanceOf(receiver).call();
+ expect(+balance).to.equal(49);
+ }
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
+ {
+ const balance = await contract.methods.balanceOf(owner).call();
+ expect(+balance).to.equal(151);
+ }
+ });
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver, 999999999999999);
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ const receiver = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, receiver, 999999999999999);
- {
- const result = await contract.methods.transfer(receiver, 50).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '50',
- }
- },
- ])
- }
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ {
+ const result = await contract.methods.transfer(receiver, 50).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ const events = normalizeEvents(result.events);
+ expect(events).to.be.deep.equal([
{
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(150);
- }
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: receiver,
+ value: '50',
+ },
+ },
+ ]);
+ }
+
+ {
+ const balance = await contract.methods.balanceOf(owner).call();
+ expect(+balance).to.equal(150);
+ }
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(50);
- }
- });
+ {
+ const balance = await contract.methods.balanceOf(receiver).call();
+ expect(+balance).to.equal(50);
+ }
+ });
});
describe('Substrate calls', () => {
- itWeb3('Events emitted for approve()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
-
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for approve()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
- const events = await recordEvents(contract, async () => {
- await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: receiver,
- value: '100',
- }
- }
- ]);
+ const events = await recordEvents(contract, async () => {
+ await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);
});
- itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Approval',
+ args: {
+ owner: subToEth(alice.address),
+ spender: receiver,
+ value: '100',
+ },
+ },
+ ]);
+ });
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
- await approveExpectSuccess(collection, 1, alice, bob, 100);
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
+ await approveExpectSuccess(collection, 1, alice, bob, 100);
- const events = await recordEvents(contract, async () => {
- await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- }
- },
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: subToEth(bob.address),
- value: '49',
- }
- }
- ]);
+ const events = await recordEvents(contract, async () => {
+ await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');
});
- itWeb3('Events emitted for transfer()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 0 }
- });
- const alice = privateKey('//Alice');
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: subToEth(alice.address),
+ to: receiver,
+ value: '51',
+ },
+ },
+ {
+ address,
+ event: 'Approval',
+ args: {
+ owner: subToEth(alice.address),
+ spender: subToEth(bob.address),
+ value: '49',
+ },
+ },
+ ]);
+ });
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for transfer()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'Fungible', decimalPoints: 0 },
+ });
+ const alice = privateKey('//Alice');
- await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });
- const events = await recordEvents(contract, async () => {
- await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- }
- },
- ]);
+ const events = await recordEvents(contract, async () => {
+ await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');
});
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: subToEth(alice.address),
+ to: receiver,
+ value: '51',
+ },
+ },
+ ]);
+ });
});
\ No newline at end of file
tests/src/eth/metadata.test.tsdiffbeforeafterboth--- a/tests/src/eth/metadata.test.ts
+++ b/tests/src/eth/metadata.test.ts
@@ -1,53 +1,58 @@
-import { expect } from "chai";
-import privateKey from "../substrate/privateKey";
-import { createCollectionExpectSuccess } from "../util/helpers";
-import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from "./util/helpers";
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { expect } from 'chai';
+import privateKey from '../substrate/privateKey';
+import { createCollectionExpectSuccess } from '../util/helpers';
+import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from './util/helpers';
import fungibleMetadataAbi from './fungibleMetadataAbi.json';
describe('Common metadata', () => {
- itWeb3('Returns collection name', async ({ api, web3 }) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: { type: 'NFT' }
- });
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
-
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const name = await contract.methods.name().call({ from: caller });
-
- expect(name).to.equal('token name');
+ itWeb3('Returns collection name', async ({ api, web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ name: 'token name',
+ mode: { type: 'NFT' },
});
+ const caller = createEthAccount(web3);
+ await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
- itWeb3('Returns symbol name', async ({ api, web3 }) => {
- const collection = await createCollectionExpectSuccess({
- tokenPrefix: 'TOK',
- mode: { type: 'NFT' }
- });
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
+ const name = await contract.methods.name().call({ from: caller });
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const symbol = await contract.methods.symbol().call({ from: caller });
+ expect(name).to.equal('token name');
+ });
- expect(symbol).to.equal('TOK');
+ itWeb3('Returns symbol name', async ({ api, web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ tokenPrefix: 'TOK',
+ mode: { type: 'NFT' },
});
+ const caller = createEthAccount(web3);
+ await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
+ const symbol = await contract.methods.symbol().call({ from: caller });
+
+ expect(symbol).to.equal('TOK');
+ });
});
describe('Fungible metadata', () => {
- itWeb3('Returns fungible decimals', async ({ api, web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'Fungible', decimalPoints: 6 }
- });
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+ itWeb3('Returns fungible decimals', async ({ api, web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'Fungible', decimalPoints: 6 },
+ });
+ const caller = createEthAccount(web3);
+ await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const decimals = await contract.methods.decimals().call({ from: caller });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
+ const decimals = await contract.methods.decimals().call({ from: caller });
- expect(+decimals).to.equal(6);
- })
-})
\ No newline at end of file
+ expect(+decimals).to.equal(6);
+ });
+});
\ No newline at end of file
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -1,280 +1,285 @@
-import privateKey from "../substrate/privateKey";
-import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from "../util/helpers";
-import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from "./util/helpers"
+//
+// 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 { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
+import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
-import { expect } from "chai";
+import { expect } from 'chai';
describe('Information getting', () => {
- itWeb3('totalSupply', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ itWeb3('totalSupply', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
- await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const totalSupply = await contract.methods.totalSupply().call();
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- const totalSupply = await contract.methods.totalSupply().call();
+ // FIXME: always equals to 0, because this method is not implemented
+ expect(totalSupply).to.equal('0');
+ });
- // FIXME: always equals to 0, because this method is not implemented
- expect(totalSupply).to.equal('0');
+ itWeb3('balanceOf', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
});
+ const alice = privateKey('//Alice');
- itWeb3('balanceOf', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ const caller = createEthAccount(web3);
+ await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- const caller = createEthAccount(web3);
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const balance = await contract.methods.balanceOf(caller).call();
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- const balance = await contract.methods.balanceOf(caller).call();
+ expect(balance).to.equal('3');
+ });
- expect(balance).to.equal('3');
+ itWeb3('ownerOf', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
});
+ const alice = privateKey('//Alice');
- itWeb3('ownerOf', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ const caller = createEthAccount(web3);
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
- const caller = createEthAccount(web3);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const owner = await contract.methods.ownerOf(tokenId).call();
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- const owner = await contract.methods.ownerOf(tokenId).call();
-
- expect(owner).to.equal(caller);
- });
+ expect(owner).to.equal(caller);
+ });
});
describe.only('Plain calls', () => {
- itWeb3('Can perform approve()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ itWeb3('Can perform approve()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
- const spender = createEthAccount(web3);
+ const spender = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ {
+ const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ const events = normalizeEvents(result.events);
+
+ expect(events).to.be.deep.equal([
{
- const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
- const events = normalizeEvents(result.events);
+ address,
+ event: 'Approval',
+ args: {
+ owner,
+ approved: spender,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ }
+ });
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner,
- approved: spender,
- tokenId: tokenId.toString(),
- }
- }
- ]);
- }
+ itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
});
-
- itWeb3('Can perform transferFrom()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ const alice = privateKey('//Alice');
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
- const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender, 999999999999999);
+ const spender = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, spender, 999999999999999);
- const receiver = createEthAccount(web3);
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ {
+ const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
+ const events = normalizeEvents(result.events);
+ expect(events).to.be.deep.equal([
{
- const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- tokenId: tokenId.toString(),
- },
- },
- ]);
- }
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: receiver,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ }
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
- }
+ {
+ const balance = await contract.methods.balanceOf(receiver).call();
+ expect(+balance).to.equal(1);
+ }
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(0);
- }
- });
+ {
+ const balance = await contract.methods.balanceOf(owner).call();
+ expect(+balance).to.equal(0);
+ }
+ });
- itWeb3('Can perform transfer()', async ({ web3, api }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ itWeb3('Can perform transfer()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ const owner = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, owner, 999999999999999);
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
- const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver, 999999999999999);
+ const receiver = createEthAccount(web3);
+ await transferBalanceToEth(api, alice, receiver, 999999999999999);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ {
+ const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
+ console.log(result);
+ const events = normalizeEvents(result.events);
+ expect(events).to.be.deep.equal([
{
- const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });
- console.log(result);
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- tokenId: tokenId.toString(),
- }
- },
- ])
- }
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: receiver,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ }
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(0);
- }
+ {
+ const balance = await contract.methods.balanceOf(owner).call();
+ expect(+balance).to.equal(0);
+ }
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
- }
- });
+ {
+ const balance = await contract.methods.balanceOf(receiver).call();
+ expect(+balance).to.equal(1);
+ }
+ });
});
describe('Substrate calls', () => {
- itWeb3('Events emitted for approve()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
-
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for approve()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
- const events = await recordEvents(contract, async () => {
- await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- approved: receiver,
- tokenId: tokenId.toString(),
- }
- }
- ]);
+ const events = await recordEvents(contract, async () => {
+ await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);
});
- itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Approval',
+ args: {
+ owner: subToEth(alice.address),
+ approved: receiver,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ });
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
- await approveExpectSuccess(collection, tokenId, alice, bob, 1);
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+ await approveExpectSuccess(collection, tokenId, alice, bob, 1);
- const events = await recordEvents(contract, async () => {
- await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- tokenId: tokenId.toString(),
- }
- },
- ]);
+ const events = await recordEvents(contract, async () => {
+ await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');
});
- itWeb3('Events emitted for transfer()', async ({ web3 }) => {
- const collection = await createCollectionExpectSuccess({
- mode: { type: 'NFT' }
- });
- const alice = privateKey('//Alice');
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: subToEth(alice.address),
+ to: receiver,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ });
- const receiver = createEthAccount(web3);
+ itWeb3('Events emitted for transfer()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
- const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+ const receiver = createEthAccount(web3);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
- const events = await recordEvents(contract, async () => {
- await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');
- });
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- tokenId: tokenId.toString(),
- }
- },
- ]);
+ const events = await recordEvents(contract, async () => {
+ await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');
});
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: subToEth(alice.address),
+ to: receiver,
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ });
});
\ No newline at end of file
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -1,70 +1,75 @@
-import { ApiPromise } from "@polkadot/api";
-import { addressToEvm, evmToAddress } from "@polkadot/util-crypto";
-import Web3 from "web3";
-import usingApi, { submitTransactionAsync } from "../../substrate/substrate-api";
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { ApiPromise } from '@polkadot/api';
+import { addressToEvm, evmToAddress } from '@polkadot/util-crypto';
+import Web3 from 'web3';
+import usingApi, { submitTransactionAsync } from '../../substrate/substrate-api';
import { IKeyringPair } from '@polkadot/types/types';
-import { expect } from "chai";
-import { getGenericResult } from "../../util/helpers";
+import { expect } from 'chai';
+import { getGenericResult } from '../../util/helpers';
let web3Connected = false;
export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
- if (web3Connected) throw new Error('do not nest usingWeb3 calls');
- web3Connected = true;
+ if (web3Connected) throw new Error('do not nest usingWeb3 calls');
+ web3Connected = true;
- const provider = new Web3.providers.WebsocketProvider("http://localhost:9944");
- const web3 = new Web3(provider);
+ const provider = new Web3.providers.WebsocketProvider('http://localhost:9944');
+ const web3 = new Web3(provider);
- try {
- return await cb(web3);
- } finally {
- // provider.disconnect(3000, 'normal disconnect');
- provider.connection.close();
- web3Connected = false;
- }
+ try {
+ return await cb(web3);
+ } finally {
+ // provider.disconnect(3000, 'normal disconnect');
+ provider.connection.close();
+ web3Connected = false;
+ }
}
export function collectionIdToAddress(address: number): string {
- if (address >= 0xffffffff || address < 0) throw new Error('id overflow');
- const buf = Buffer.from([0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,
- address >> 24,
- (address >> 16) & 0xff,
- (address >> 8) & 0xff,
- address & 0xff,
- ]);
- return Web3.utils.toChecksumAddress('0x' + buf.toString('hex'));
+ if (address >= 0xffffffff || address < 0) throw new Error('id overflow');
+ const buf = Buffer.from([0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,
+ address >> 24,
+ (address >> 16) & 0xff,
+ (address >> 8) & 0xff,
+ address & 0xff,
+ ]);
+ return Web3.utils.toChecksumAddress('0x' + buf.toString('hex'));
}
export function createEthAccount(web3: Web3) {
- const account = web3.eth.accounts.create();
- web3.eth.accounts.wallet.add(account.privateKey);
- return account.address;
+ const account = web3.eth.accounts.create();
+ web3.eth.accounts.wallet.add(account.privateKey);
+ return account.address;
}
export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount: number) {
- const tx = api.tx.balances.transfer(evmToAddress(target), amount);
- const events = await submitTransactionAsync(source, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ const tx = api.tx.balances.transfer(evmToAddress(target), amount);
+ const events = await submitTransactionAsync(source, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
}
export async function itWeb3(name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
- let i: any = it;
- if (opts.only) i = i.only;
- else if (opts.skip) i = i.skip;
- i(name, async () => {
- await usingApi(async api => {
- await usingWeb3(async web3 => {
- await cb({ api, web3 });
- });
- });
+ let i: any = it;
+ if (opts.only) i = i.only;
+ else if (opts.skip) i = i.skip;
+ i(name, async () => {
+ await usingApi(async api => {
+ await usingWeb3(async web3 => {
+ await cb({ api, web3 });
+ });
});
+ });
}
itWeb3.only = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, { only: true });
itWeb3.skip = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, { skip: true });
export async function generateSubstrateEthPair(web3: Web3) {
- let account = web3.eth.accounts.create();
- const evm = evmToAddress(account.address);
+ const account = web3.eth.accounts.create();
+ evmToAddress(account.address);
}
type NormalizedEvent = {
@@ -74,43 +79,43 @@
};
export function normalizeEvents(events: any): NormalizedEvent[] {
- const output = [];
- for (let key of Object.keys(events)) {
- if (key.match(/^[0-9]+$/)) {
- output.push(events[key]);
- } else if (Array.isArray(events[key])) {
- output.push(...events[key]);
- } else {
- output.push(events[key]);
- }
+ const output = [];
+ for (const key of Object.keys(events)) {
+ if (key.match(/^[0-9]+$/)) {
+ output.push(events[key]);
+ } else if (Array.isArray(events[key])) {
+ output.push(...events[key]);
+ } else {
+ output.push(events[key]);
}
- output.sort((a, b) => a.logIndex - b.logIndex);
- return output.map(({ address, event, returnValues }) => {
- const args: { [key: string]: string } = {};
- for (let key of Object.keys(returnValues)) {
- if (!key.match(/^[0-9]+$/)) {
- args[key] = returnValues[key];
- }
- }
- return {
- address,
- event,
- args,
- };
- });
+ }
+ output.sort((a, b) => a.logIndex - b.logIndex);
+ return output.map(({ address, event, returnValues }) => {
+ const args: { [key: string]: string } = {};
+ for (const key of Object.keys(returnValues)) {
+ if (!key.match(/^[0-9]+$/)) {
+ args[key] = returnValues[key];
+ }
+ }
+ return {
+ address,
+ event,
+ args,
+ };
+ });
}
export async function recordEvents(contract: any, action: () => Promise<void>): Promise<NormalizedEvent[]> {
- const out: any = [];
- contract.events.allEvents((_: any, event: any) => {
- out.push(event);
- });
- await action();
- return normalizeEvents(out);
+ const out: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ out.push(event);
+ });
+ await action();
+ return normalizeEvents(out);
}
export function subToEth(eth: string): string {
- const bytes = addressToEvm(eth);
- const string = '0x' + Buffer.from(bytes).toString('hex');
- return Web3.utils.toChecksumAddress(string);
+ const bytes = addressToEvm(eth);
+ const string = '0x' + Buffer.from(bytes).toString('hex');
+ return Web3.utils.toChecksumAddress(string);
}
\ No newline at end of file
tests/src/inflation.test.tsdiffbeforeafterboth--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -5,25 +5,13 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from "./substrate/substrate-api";
-import privateKey from "./substrate/privateKey";
+import { default as usingApi } from './substrate/substrate-api';
import { BigNumber } from 'bignumber.js';
-import { IKeyringPair } from '@polkadot/types/types';
chai.use(chaiAsPromised);
const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
describe('integration test: Inflation', () => {
- before(async () => {
- await usingApi(async (api) => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
it('First year inflation is 10%', async () => {
await usingApi(async (api) => {
tests/src/overflow.test.tsdiffbeforeafterboth--- a/tests/src/overflow.test.ts
+++ b/tests/src/overflow.test.ts
@@ -3,65 +3,65 @@
// file 'LICENSE', which is part of this source code package.
//
-import { IKeyringPair } from "@polkadot/types/types";
+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";
+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;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- });
+ 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 } });
+ 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: 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');
+ 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);
- });
+ 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 } });
+ 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);
- });
+ 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 } });
+ 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');
+ 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');
+ 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);
+ 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');
- });
+ expect(await getFungibleBalance(fungibleCollectionId, charlie.address)).to.equal(U128_MAX);
+ expect((await getAllowance(fungibleCollectionId, 0, alice.address, bob.address)).toString()).to.equal('1');
+ });
});
tests/src/pallet-presence.test.tsdiffbeforeafterboth--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -3,9 +3,9 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from "@polkadot/api";
-import { expect } from "chai";
-import usingApi from "./substrate/substrate-api";
+import { ApiPromise } from '@polkadot/api';
+import { expect } from 'chai';
+import usingApi from './substrate/substrate-api';
function getModuleNames(api: ApiPromise): string[] {
return api.runtimeMetadata.asLatest.modules.map(m => m.name.toString().toLowerCase());
@@ -14,12 +14,12 @@
// Pallets that must always be present
const requiredPallets = [
'nft', 'inflation', 'balances', 'contracts', 'randomnesscollectiveflip', 'system', 'timestamp', 'transactionpayment', 'treasury', 'vesting', 'evm', 'ethereum',
- 'scheduler', 'nftpayment', 'charging'
+ 'scheduler', 'nftpayment', 'charging',
];
// Pallets that depend on consensus and governance configuration
const consensusPallets = [
- 'sudo', 'aura'
+ 'sudo', 'aura',
];
describe('Pallet presence', () => {
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -5,27 +5,21 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
+import { default as usingApi, submitTransactionExpectFailAsync } from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
setCollectionSponsorExpectSuccess,
destroyCollectionExpectSuccess,
- setCollectionSponsorExpectFailure,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
createItemExpectSuccess,
findUnusedAddress,
- getGenericResult,
- enableWhiteListExpectSuccess,
- enablePublicMintingExpectSuccess,
- addToWhiteListExpectSuccess,
removeCollectionSponsorExpectSuccess,
removeCollectionSponsorExpectFailure,
normalizeAccountId,
-} from "./util/helpers";
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
-import type { AccountId } from '@polkadot/types/interfaces';
+} from './util/helpers';
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
import { BigNumber } from 'bignumber.js';
chai.use(chaiAsPromised);
@@ -33,16 +27,14 @@
let alice: IKeyringPair;
let bob: IKeyringPair;
-let charlie: IKeyringPair;
describe('integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
- charlie = keyring.addFromUri(`//Charlie`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
});
});
@@ -65,7 +57,7 @@
const badTransaction = async function () {
await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);
};
- await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");
+ await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');
const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;
@@ -95,19 +87,18 @@
describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- alice = keyring.addFromUri(`//Alice`);
- bob = keyring.addFromUri(`//Bob`);
- charlie = keyring.addFromUri(`//Charlie`);
+ alice = keyring.addFromUri('//Alice');
+ bob = keyring.addFromUri('//Bob');
});
});
it('(!negative test!) Remove sponsor for a collection that never existed', async () => {
// Find the collection that never existed
- const collectionId = 0;
+ let collectionId = 0;
await usingApi(async (api) => {
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
});
await removeCollectionSponsorExpectFailure(collectionId);
tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractWhiteList.test.ts
+++ b/tests/src/removeFromContractWhiteList.test.ts
@@ -3,79 +3,79 @@
// 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";
-import { addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess } from "./util/helpers";
+import privateKey from './substrate/privateKey';
+import usingApi from './substrate/substrate-api';
+import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from './util/contracthelpers';
+import { addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess } from './util/helpers';
import { IKeyringPair } from '@polkadot/types/types';
-import { expect } from "chai";
+import { expect } from 'chai';
describe('Integration Test removeFromContractWhiteList', () => {
- let bob: IKeyringPair;
+ let bob: IKeyringPair;
- before(async () => {
- await usingApi(async () => {
- bob = privateKey('//Bob');
- });
+ before(async () => {
+ await usingApi(async () => {
+ bob = privateKey('//Bob');
});
+ });
- it('user is no longer whitelisted after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ it('user is no longer whitelisted after removal', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- expect(await isWhitelistedInContract(flipper.address, bob.address)).to.be.false;
- });
+ expect(await isWhitelistedInContract(flipper.address, bob.address)).to.be.false;
});
+ });
- it('user can\'t execute contract after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
- await toggleContractWhitelistExpectSuccess(deployer, flipper.address.toString(), true);
+ it('user can\'t execute contract after removal', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
+ await toggleContractWhitelistExpectSuccess(deployer, flipper.address.toString(), true);
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await toggleFlipValueExpectSuccess(bob, flipper);
+ await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await toggleFlipValueExpectSuccess(bob, flipper);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await toggleFlipValueExpectFailure(bob, flipper);
- });
+ await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await toggleFlipValueExpectFailure(bob, flipper);
});
+ });
- it('can be called twice', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ it('can be called twice', async () => {
+ await usingApi(async (api) => {
+ const [flipper, deployer] = await deployFlipper(api);
- await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
- });
+ await addToContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
+ await removeFromContractWhiteListExpectSuccess(deployer, flipper.address.toString(), bob.address);
});
+ });
});
describe('Negative Integration Test removeFromContractWhiteList', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
});
+ });
- it('fails when called with non-contract address', async () => {
- await usingApi(async () => {
- await removeFromContractWhiteListExpectFailure(alice, alice.address, bob.address);
- });
+ it('fails when called with non-contract address', async () => {
+ await usingApi(async () => {
+ await removeFromContractWhiteListExpectFailure(alice, alice.address, bob.address);
});
+ });
- it('fails when executed by non owner', async () => {
- await usingApi(async (api) => {
- const [flipper, _] = await deployFlipper(api);
+ it('fails when executed by non owner', async () => {
+ await usingApi(async (api) => {
+ const [flipper] = await deployFlipper(api);
- await removeFromContractWhiteListExpectFailure(alice, flipper.address.toString(), bob.address);
- });
+ await removeFromContractWhiteListExpectFailure(alice, flipper.address.toString(), bob.address);
});
+ });
});
tests/src/removeFromWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromWhiteList.test.ts
+++ b/tests/src/removeFromWhiteList.test.ts
@@ -28,7 +28,7 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
@@ -62,7 +62,7 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
alice = privateKey('//Alice');
bob = privateKey('//Bob');
});
tests/src/rpc.load.tsdiffbeforeafterboth--- a/tests/src/rpc.load.ts
+++ b/tests/src/rpc.load.ts
@@ -3,24 +3,22 @@
// file 'LICENSE', which is part of this source code package.
//
-import { expect, assert } from "chai";
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import { IKeyringPair } from "@polkadot/types/types";
-import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";
-import { ApiPromise, Keyring } from "@polkadot/api";
-import { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types";
+import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import { IKeyringPair } from '@polkadot/types/types';
+import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from '@polkadot/api-contract';
+import { ApiPromise, Keyring } from '@polkadot/api';
import { BigNumber } from 'bignumber.js';
-import { findUnusedAddress } from './util/helpers'
-import fs from "fs";
-import privateKey from "./substrate/privateKey";
+import { findUnusedAddress } from './util/helpers';
+import fs from 'fs';
+import privateKey from './substrate/privateKey';
const value = 0;
const gasLimit = 500000n * 1000000n;
-const endowment = `1000000000000000`;
-
+const endowment = '1000000000000000';
+/*eslint no-async-promise-executor: "off"*/
function deployBlueprint(alice: IKeyringPair, code: CodePromise): Promise<Blueprint> {
- return new Promise<Blueprint>(async (resolve, reject) => {
+ return new Promise<Blueprint>(async (resolve) => {
const unsub = await code
.createBlueprint()
.signAndSend(alice, (result) => {
@@ -29,20 +27,21 @@
resolve(result.blueprint);
unsub();
}
- })
+ });
});
}
+/*eslint no-async-promise-executor: "off"*/
function deployContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {
- return new Promise<any>(async (resolve, reject) => {
+ return new Promise<any>(async (resolve) => {
const unsub = await blueprint.tx
- .new(endowment, gasLimit)
- .signAndSend(alice, (result) => {
- if (result.status.isInBlock || result.status.isFinalized) {
- unsub();
- resolve(result);
- }
- });
+ .new(endowment, gasLimit)
+ .signAndSend(alice, (result) => {
+ if (result.status.isInBlock || result.status.isFinalized) {
+ unsub();
+ resolve(result);
+ }
+ });
});
}
@@ -52,7 +51,7 @@
// Transfer balance to it
const keyring = new Keyring({ type: 'sr25519' });
- const alice = keyring.addFromUri(`//Alice`);
+ const alice = keyring.addFromUri('//Alice');
let amount = new BigNumber(endowment);
amount = amount.plus(1e15);
const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());
@@ -81,7 +80,7 @@
const result = await contract.query.get(deployer.address, value, gasLimit);
if(!result.result.isSuccess) {
- throw `Failed to get value`;
+ throw 'Failed to get value';
}
return result.result.asSuccess.data;
}
@@ -95,6 +94,8 @@
let microsec1 = hrTime[0] * 1000000 + hrTime[1] / 1000;
let rate = 0;
const checkPoint = 1000;
+
+ /* eslint no-constant-condition: "off" */
while (true) {
await api.rpc.system.chain();
count++;
@@ -102,7 +103,7 @@
if (count % checkPoint == 0) {
hrTime = process.hrtime();
- let microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
+ const microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
rate = 1000000*checkPoint/(microsec2 - microsec1);
microsec1 = microsec2;
}
@@ -117,7 +118,7 @@
const [contract, deployer] = await deployLoadTester(api);
// Fill smart contract up with data
- const bob = privateKey("//Bob");
+ const bob = privateKey('//Bob');
const tx = contract.tx.bloat(value, gasLimit, 200);
await submitTransactionAsync(bob, tx);
@@ -127,6 +128,8 @@
let microsec1 = hrTime[0] * 1000000 + hrTime[1] / 1000;
let rate = 0;
const checkPoint = 10;
+
+ /* eslint no-constant-condition: "off" */
while (true) {
await getScData(contract, deployer);
count++;
@@ -134,7 +137,7 @@
if (count % checkPoint == 0) {
hrTime = process.hrtime();
- let microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
+ const microsec2 = hrTime[0] * 1000000 + hrTime[1] / 1000;
rate = 1000000*checkPoint/(microsec2 - microsec1);
microsec1 = microsec2;
}
tests/src/scheduler.test.tsdiffbeforeafterboth--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -3,7 +3,6 @@
// 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';
@@ -11,34 +10,16 @@
import {
createItemExpectSuccess,
createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
- findNotExistingCollection,
- queryCollectionExpectSuccess,
- setOffchainSchemaExpectFailure,
- setOffchainSchemaExpectSuccess,
- transferExpectSuccess,
scheduleTransferExpectSuccess,
setCollectionSponsorExpectSuccess,
- confirmSponsorshipExpectSuccess
+ confirmSponsorshipExpectSuccess,
} from './util/helpers';
-
chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-const DATA = [1, 2, 3, 4];
describe('Integration Test scheduler base transaction', () => {
- let alice: IKeyringPair;
-
- before(async () => {
+ it('User can transfer owned token with delay (scheduler)', async () => {
await usingApi(async () => {
- alice = privateKey('//Alice');
- });
- });
-
- it('User can transfer owned token with delay (scheduler)', async () => {
- await usingApi(async (api) => {
const Alice = privateKey('//Alice');
const Bob = privateKey('//Bob');
// nft
@@ -50,45 +31,4 @@
await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
});
});
-
-
});
-
-// describe('Negative Integration Test setOffchainSchema', () => {
-// let alice: IKeyringPair;
-// let bob: IKeyringPair;
-
-// let validCollectionId: number;
-
-// before(async () => {
-// await usingApi(async () => {
-// alice = privateKey('//Alice');
-// bob = privateKey('//Bob');
-
-// validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-// });
-// });
-
-// it('fails on not existing collection id', async () => {
-// const nonExistingCollectionId = await usingApi(findNotExistingCollection);
-
-// await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);
-// });
-
-// it('fails on destroyed collection id', async () => {
-// const destroyedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
-// await destroyCollectionExpectSuccess(destroyedCollectionId);
-
-// await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);
-// });
-
-// it('fails on too long data', async () => {
-// const tooLongData = new Array(4097).fill(0xff);
-
-// await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);
-// });
-
-// it('fails on execution by non-owner', async () => {
-// await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);
-// });
-// });
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -50,7 +50,7 @@
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
},
);
const events = await submitTransactionAsync(alice, tx);
@@ -73,13 +73,13 @@
it('Set the same token limit twice', async () => {
await usingApi(async (api: ApiPromise) => {
- let collectionLimits = {
+ const collectionLimits = {
AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
SponsoredMintSize: sponsoredDataSize,
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
};
// The first time
@@ -173,7 +173,7 @@
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: false,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
});
await setCollectionLimitsExpectFailure(alice, collectionId, {
AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
@@ -181,7 +181,7 @@
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
});
});
@@ -193,7 +193,7 @@
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: false
+ OwnerCanDestroy: false,
});
await setCollectionLimitsExpectFailure(alice, collectionId, {
AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
@@ -201,21 +201,21 @@
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
});
});
it('Setting the higher token limit fails', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const collectionId = await createCollectionExpectSuccess();
- let collectionLimits = {
+ const collectionLimits = {
AccountTokenOwnershipLimit: accountTokenOwnershipLimit,
SponsoredMintSize: sponsoredDataSize,
TokenLimit: tokenLimit,
SponsorTimeout: sponsorTimeout,
OwnerCanTransfer: true,
- OwnerCanDestroy: true
+ OwnerCanDestroy: true,
};
// The first time
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -5,22 +5,21 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { default as usingApi } from "./substrate/substrate-api";
-import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from "./util/helpers";
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
+import { default as usingApi } from './substrate/substrate-api';
+import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from './util/helpers';
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
chai.use(chaiAsPromised);
-const expect = chai.expect;
let bob: IKeyringPair;
describe('integration test: ext. setCollectionSponsor():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- bob = keyring.addFromUri(`//Bob`);
+ bob = keyring.addFromUri('//Bob');
});
});
@@ -46,7 +45,7 @@
const collectionId = await createCollectionExpectSuccess();
const keyring = new Keyring({ type: 'sr25519' });
- const charlie = keyring.addFromUri(`//Charlie`);
+ const charlie = keyring.addFromUri('//Charlie');
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
});
@@ -54,9 +53,9 @@
describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
- bob = keyring.addFromUri(`//Bob`);
+ bob = keyring.addFromUri('//Bob');
});
});
@@ -66,9 +65,9 @@
});
it('(!negative test!) Add sponsor to a collection that never existed', async () => {
// Find the collection that never existed
- const collectionId = 0;
+ let collectionId = 0;
await usingApi(async (api) => {
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
});
await setCollectionSponsorExpectFailure(collectionId, bob.address);
tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setConstOnChainSchema.test.ts
+++ b/tests/src/setConstOnChainSchema.test.ts
@@ -23,7 +23,7 @@
let largeShema: any;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
Alice = keyring.addFromUri('//Alice');
Bob = keyring.addFromUri('//Bob');
@@ -35,7 +35,7 @@
describe('Integration Test ext. setConstOnChainSchema()', () => {
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner).to.be.deep.eq(normalizeAccountId(Alice.address));
@@ -45,12 +45,12 @@
});
it('Checking collection data using the ConstOnChainSchema parameter', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
- await submitTransactionAsync(Alice, setShema);
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
+ await submitTransactionAsync(Alice, setShema);
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);
});
});
tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth--- a/tests/src/setContractSponsoringRateLimit.test.ts
+++ b/tests/src/setContractSponsoringRateLimit.test.ts
@@ -59,7 +59,7 @@
it('fails when called by non-owning user', async () => {
await usingApi(async (api) => {
- const [flipper, _] = await deployFlipper(api);
+ const [flipper] = await deployFlipper(api);
await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);
});
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -1,95 +1,94 @@
-//
-// This file is subject to the terms and conditions defined in
-// file 'LICENSE', which is part of this source code package.
-//
-
-// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
-import { ApiPromise, Keyring } from '@polkadot/api';
-import { IKeyringPair } from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
-import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
- addToWhiteListExpectSuccess,
- createCollectionExpectSuccess,
- createItemExpectSuccess,
- destroyCollectionExpectSuccess,
- enablePublicMintingExpectSuccess,
- enableWhiteListExpectSuccess,
- normalizeAccountId,
-} from './util/helpers';
-import { utf16ToStr } from './util/util';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let Alice: IKeyringPair;
-let Bob: IKeyringPair;
-
-describe('Integration Test setPublicAccessMode(): ', () => {
- before(async () => {
- await usingApi(async (api) => {
- Alice = privateKey('//Alice');
- Bob = privateKey('//Bob');
- });
- });
-
- it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
- await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
- });
- });
-
- it('Whitelisted collection limits', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionId = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enablePublicMintingExpectSuccess(Alice, collectionId);
- const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');
- await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
- });
- });
-});
-
-describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {
- it('Set a non-existent collection', async () => {
- await usingApi(async (api: ApiPromise) => {
- // tslint:disable-next-line: radix
- const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
- });
- });
-
- it('Set the collection that has been deleted', async () => {
- await usingApi(async (api: ApiPromise) => {
- // tslint:disable-next-line: no-bitwise
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
- });
- });
-
- it('Re-set the list mode already set in quantity', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionId: number = await createCollectionExpectSuccess();
- await enableWhiteListExpectSuccess(Alice, collectionId);
- await enableWhiteListExpectSuccess(Alice, collectionId);
- });
- });
-
- it('Execute method not on behalf of the collection owner', async () => {
- await usingApi(async (api: ApiPromise) => {
- // tslint:disable-next-line: no-bitwise
- const collectionId = await createCollectionExpectSuccess();
- const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
- await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
- });
- });
-});
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
+import { ApiPromise } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import {
+ addToWhiteListExpectSuccess,
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
+ enablePublicMintingExpectSuccess,
+ enableWhiteListExpectSuccess,
+ normalizeAccountId,
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let Alice: IKeyringPair;
+let Bob: IKeyringPair;
+
+describe('Integration Test setPublicAccessMode(): ', () => {
+ before(async () => {
+ await usingApi(async () => {
+ Alice = privateKey('//Alice');
+ Bob = privateKey('//Bob');
+ });
+ });
+
+ it('Run extrinsic with collection id parameters, set the whitelist mode for the collection', async () => {
+ await usingApi(async () => {
+ const collectionId: number = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ await addToWhiteListExpectSuccess(Alice, collectionId, Bob.address);
+ await createItemExpectSuccess(Bob, collectionId, 'NFT', Bob.address);
+ });
+ });
+
+ it('Whitelisted collection limits', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const collectionId = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enablePublicMintingExpectSuccess(Alice, collectionId);
+ const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(Bob.address), 'NFT');
+ await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
+ });
+ });
+});
+
+describe('Negative Integration Test ext. setPublicAccessMode(): ', () => {
+ it('Set a non-existent collection', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ // tslint:disable-next-line: radix
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('Set the collection that has been deleted', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ await destroyCollectionExpectSuccess(collectionId);
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+
+ it('Re-set the list mode already set in quantity', async () => {
+ await usingApi(async () => {
+ const collectionId: number = await createCollectionExpectSuccess();
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ await enableWhiteListExpectSuccess(Alice, collectionId);
+ });
+ });
+
+ it('Execute method not on behalf of the collection owner', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
+ await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
+ });
+ });
+});
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -103,7 +103,7 @@
it('execute setSchemaVersion with not correct schema version', async () => {
await usingApi(async (api: ApiPromise) => {
const consoleError = console.error;
- console.error = (message: string) => {};
+ console.error = () => {};
try {
tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');
await submitTransactionAsync(alice, tx);
tests/src/setVariableMetaData.test.tsdiffbeforeafterboth--- a/tests/src/setVariableMetaData.test.ts
+++ b/tests/src/setVariableMetaData.test.ts
@@ -49,7 +49,7 @@
});
describe('Negative Integration Test setVariableMetaData', () => {
- let data = [1];
+ const data = [1];
let alice: IKeyringPair;
let bob: IKeyringPair;
@@ -69,7 +69,7 @@
it('fails on not existing collection id', async () => {
await usingApi(async api => {
- let nonExistingCollectionId = await findNotExistingCollection(api);
+ const nonExistingCollectionId = await findNotExistingCollection(api);
await setVariableMetaDataExpectFailure(alice, nonExistingCollectionId, 1, data);
});
});
tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setVariableOnChainSchema.test.ts
+++ b/tests/src/setVariableOnChainSchema.test.ts
@@ -23,7 +23,7 @@
let largeSchema: any;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const keyring = new Keyring({ type: 'sr25519' });
Alice = keyring.addFromUri('//Alice');
Bob = keyring.addFromUri('//Bob');
@@ -35,7 +35,7 @@
describe('Integration Test ext. setVariableOnChainSchema()', () => {
it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api) => {
const collectionId = await createCollectionExpectSuccess();
const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
expect(collection.Owner).to.be.deep.eq(normalizeAccountId(Alice.address));
@@ -45,12 +45,12 @@
});
it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
- await submitTransactionAsync(Alice, setSchema);
- const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
- expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
+ await usingApi(async (api) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
+ await submitTransactionAsync(Alice, setSchema);
+ const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
+ expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
});
});
tests/src/substrate/privateKey.tsdiffbeforeafterboth--- a/tests/src/substrate/privateKey.ts
+++ b/tests/src/substrate/privateKey.ts
@@ -3,8 +3,8 @@
// file 'LICENSE', which is part of this source code package.
//
-import { Keyring } from "@polkadot/api";
-import { IKeyringPair } from "@polkadot/types/types";
+import { Keyring } from '@polkadot/api';
+import { IKeyringPair } from '@polkadot/types/types';
export default function privateKey(account: string): IKeyringPair {
const keyring = new Keyring({ type: 'sr25519' });
tests/src/substrate/promisify-substrate.tsdiffbeforeafterboth--- a/tests/src/substrate/promisify-substrate.ts
+++ b/tests/src/substrate/promisify-substrate.ts
@@ -3,7 +3,7 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from "@polkadot/api";
+import { ApiPromise } from '@polkadot/api';
type PromiseType<T> = T extends PromiseLike<infer TInner> ? TInner : T;
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -3,15 +3,15 @@
// file 'LICENSE', which is part of this source code package.
//
-import { WsProvider, ApiPromise } from "@polkadot/api";
+import { WsProvider, ApiPromise } from '@polkadot/api';
import { EventRecord } from '@polkadot/types/interfaces/system/types';
import { ExtrinsicStatus } from '@polkadot/types/interfaces/author/types';
-import { IKeyringPair } from "@polkadot/types/types";
+import { IKeyringPair } from '@polkadot/types/types';
-import config from "../config";
-import promisifySubstrate from "./promisify-substrate";
-import { ApiOptions, SubmittableExtrinsic, ApiTypes } from "@polkadot/api/types";
-import rtt from "../../../runtime_types.json";
+import config from '../config';
+import promisifySubstrate from './promisify-substrate';
+import { ApiOptions, SubmittableExtrinsic, ApiTypes } from '@polkadot/api/types';
+import rtt from '../../../runtime_types.json';
function defaultApiOptions(): ApiOptions {
const wsProvider = new WsProvider(config.substrateUrl);
@@ -20,15 +20,15 @@
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);
+ const 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)
const consoleErr = console.error;
console.error = (message: string) => {
- if (message.includes("StorageChangeSet:: WebSocket is not connected") || message.includes("2021-")) {}
- else consoleErr(message);
+ if (!message.includes('StorageChangeSet:: WebSocket is not connected') || message.includes('2021-'))
+ consoleErr(message);
};
try {
@@ -72,6 +72,7 @@
export function
submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {
+ /* eslint no-async-promise-executor: "off" */
return new Promise(async (resolve, reject) => {
try {
await transaction.signAndSend(sender, ({ events = [], status }) => {
@@ -97,6 +98,7 @@
console.error = () => {};
console.log = () => {};
+ /* eslint no-async-promise-executor: "off" */
return new Promise<EventRecord[]>(async function(res, rej) {
const resolve = (rec: EventRecord[]) => {
setTimeout(() => {
tests/src/substrate/wait-new-blocks.tsdiffbeforeafterboth--- a/tests/src/substrate/wait-new-blocks.ts
+++ b/tests/src/substrate/wait-new-blocks.ts
@@ -3,15 +3,16 @@
// file 'LICENSE', which is part of this source code package.
//
-import { ApiPromise } from "@polkadot/api";
+import { ApiPromise } from '@polkadot/api';
-export default function waitNewBlocks(api: ApiPromise, blocksCount: number = 1): Promise<void> {
- const promise = new Promise<void>(async (resolve, reject) => {
+/* eslint no-async-promise-executor: "off" */
+export default function waitNewBlocks(api: ApiPromise, blocksCount = 1): Promise<void> {
+ const promise = new Promise<void>(async (resolve) => {
- const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
- if(blocksCount > 0) {
+ const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {
+ if (blocksCount > 0) {
blocksCount--;
- }else {
+ } else {
unsubscribe();
resolve();
}
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractWhiteList.test.ts
+++ b/tests/src/toggleContractWhiteList.test.ts
@@ -3,17 +3,17 @@
// file 'LICENSE', which is part of this source code package.
//
-import chai from "chai";
+import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
-import privateKey from "./substrate/privateKey";
+import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
import {
deployFlipper,
- getFlipValue
-} from "./util/contracthelpers";
+ getFlipValue,
+} from './util/contracthelpers';
import {
- getGenericResult
-} from "./util/helpers"
+ getGenericResult,
+} from './util/helpers';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -23,7 +23,7 @@
describe('Integration Test toggleContractWhiteList', () => {
- it(`Enable white list contract mode`, async () => {
+ it('Enable white list contract mode', async () => {
await usingApi(async api => {
const [contract, deployer] = await deployFlipper(api);
@@ -38,9 +38,9 @@
});
});
- it(`Only whitelisted account can call contract`, async () => {
+ it('Only whitelisted account can call contract', async () => {
await usingApi(async api => {
- const bob = privateKey("//Bob");
+ const bob = privateKey('//Bob');
const [contract, deployer] = await deployFlipper(api);
@@ -48,59 +48,59 @@
const flip = contract.exec('flip', value, gasLimit);
await submitTransactionAsync(bob, flip);
const flipValueAfter = await getFlipValue(contract,deployer);
- expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);
+ expect(flipValueAfter).to.be.eq(!flipValueBefore, 'Anyone can call new contract.');
const deployerCanFlip = async () => {
- let flipValueBefore = await getFlipValue(contract, deployer);
+ const flipValueBefore = await getFlipValue(contract, deployer);
const deployerFlip = contract.exec('flip', value, gasLimit);
await submitTransactionAsync(deployer, deployerFlip);
const aliceFlip1Response = await getFlipValue(contract, deployer);
- expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);
+ expect(aliceFlip1Response).to.be.eq(!flipValueBefore, 'Deployer always can flip.');
};
await deployerCanFlip();
flipValueBefore = await getFlipValue(contract, deployer);
const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);
+ await submitTransactionAsync(deployer, enableWhiteListTx);
const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);
await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;
const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);
- expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);
+ expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, 'Enabling whitelist doesn\'t make it possible to call contract for everyone.');
await deployerCanFlip();
flipValueBefore = await getFlipValue(contract, deployer);
const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);
- const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);
+ await submitTransactionAsync(deployer, addBobToWhiteListTx);
const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);
await submitTransactionAsync(bob, flipWithWhitelistedBob);
const flipAfterWhiteListed = await getFlipValue(contract,deployer);
- expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);
+ expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, 'Bob was whitelisted, now he can flip.');
await deployerCanFlip();
flipValueBefore = await getFlipValue(contract, deployer);
const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);
- const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);
+ await submitTransactionAsync(deployer, removeBobFromWhiteListTx);
const bobRemoved = contract.exec('flip', value, gasLimit);
await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
const afterBobRemoved = await getFlipValue(contract, deployer);
- expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);
+ expect(afterBobRemoved).to.be.eq(flipValueBefore, 'Bob can\'t call contract, now when he is removeed from white list.');
await deployerCanFlip();
flipValueBefore = await getFlipValue(contract, deployer);
const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
- const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);
+ await submitTransactionAsync(deployer, disableWhiteListTx);
const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);
await submitTransactionAsync(bob, whiteListDisabledFlip);
const afterWhiteListDisabled = await getFlipValue(contract,deployer);
- expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);
+ expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, 'Anyone can call contract with disabled whitelist.');
});
});
- it(`Enabling white list repeatedly should not produce errors`, async () => {
+ it('Enabling white list repeatedly should not produce errors', async () => {
await usingApi(async api => {
const [contract, deployer] = await deployFlipper(api);
@@ -123,10 +123,10 @@
describe('Negative Integration Test toggleContractWhiteList', () => {
- it(`Enable white list for a non-contract`, async () => {
+ it('Enable white list for a non-contract', async () => {
await usingApi(async api => {
- const alice = privateKey("//Alice");
- const bobGuineaPig = privateKey("//Bob");
+ const alice = privateKey('//Alice');
+ const bobGuineaPig = privateKey('//Bob');
const enabledBefore = (await api.query.nft.contractWhiteListEnabled(bobGuineaPig.address)).toJSON();
const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(bobGuineaPig.address, true);
@@ -138,10 +138,10 @@
});
});
- it(`Enable white list using a non-owner address`, async () => {
+ it('Enable white list using a non-owner address', async () => {
await usingApi(async api => {
- const bob = privateKey("//Bob");
- const [contract, deployer] = await deployFlipper(api);
+ const bob = privateKey('//Bob');
+ const [contract] = await deployFlipper(api);
const enabledBefore = (await api.query.nft.contractWhiteListEnabled(contract.address)).toJSON();
const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
tests/src/transfer.nload.tsdiffbeforeafterboth--- a/tests/src/transfer.nload.ts
+++ b/tests/src/transfer.nload.ts
@@ -1,9 +1,14 @@
-import { ApiPromise } from "@polkadot/api";
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import { ApiPromise } from '@polkadot/api';
import { IKeyringPair } from '@polkadot/types/types';
-import privateKey from "./substrate/privateKey";
-import usingApi, { submitTransactionAsync } from "./substrate/substrate-api";
-import waitNewBlocks from "./substrate/wait-new-blocks";
-import { findUnusedAddresses } from "./util/helpers";
+import privateKey from './substrate/privateKey';
+import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import waitNewBlocks from './substrate/wait-new-blocks';
+import { findUnusedAddresses } from './util/helpers';
import * as cluster from 'cluster';
import os from 'os';
@@ -12,102 +17,102 @@
let counters: { [key: string]: number } = {};
function increaseCounter(name: string, amount: number) {
- if (!counters[name]) {
- counters[name] = 0;
- }
- counters[name] += amount;
+ if (!counters[name]) {
+ counters[name] = 0;
+ }
+ counters[name] += amount;
}
function flushCounterToMaster() {
- if (Object.keys(counters).length === 0) {
- return;
- }
+ if (Object.keys(counters).length === 0) {
+ return;
+ }
process.send!(counters);
counters = {};
}
async function distributeBalance(source: IKeyringPair, api: ApiPromise, totalAmount: bigint, stages: number) {
- let accounts = [source];
- // we don't need source in output array
- const failedAccounts = [0];
+ const accounts = [source];
+ // we don't need source in output array
+ const failedAccounts = [0];
- const finalUserAmount = 2 ** stages - 1;
- accounts.push(...await findUnusedAddresses(api, finalUserAmount));
- // findUnusedAddresses produces at least 1 request per user
- increaseCounter('requests', finalUserAmount);
+ const finalUserAmount = 2 ** stages - 1;
+ accounts.push(...await findUnusedAddresses(api, finalUserAmount));
+ // findUnusedAddresses produces at least 1 request per user
+ increaseCounter('requests', finalUserAmount);
- for (let stage = 0; stage < stages; stage++) {
- let usersWithBalance = 2 ** stage;
- let amount = totalAmount / (2n ** BigInt(stage)) - FEE * BigInt(stage);
- // console.log(`Stage ${stage}/${stages}, ${usersWithBalance} => ${usersWithBalance * 2} = ${amount}`);
- let txs = [];
- for (let i = 0; i < usersWithBalance; i++) {
- let newUser = accounts[i + usersWithBalance];
- // console.log(`${accounts[i].address} => ${newUser.address} = ${amountToSplit}`);
- const tx = api.tx.balances.transfer(newUser.address, amount);
- txs.push(submitTransactionAsync(accounts[i], tx).catch(e => {
- failedAccounts.push(i + usersWithBalance);
- increaseCounter('txFailed', 1);
- }));
- increaseCounter('tx', 1);
- }
- await Promise.all(txs);
+ for (let stage = 0; stage < stages; stage++) {
+ const usersWithBalance = 2 ** stage;
+ const amount = totalAmount / (2n ** BigInt(stage)) - FEE * BigInt(stage);
+ // console.log(`Stage ${stage}/${stages}, ${usersWithBalance} => ${usersWithBalance * 2} = ${amount}`);
+ const txs = [];
+ for (let i = 0; i < usersWithBalance; i++) {
+ const newUser = accounts[i + usersWithBalance];
+ // console.log(`${accounts[i].address} => ${newUser.address} = ${amountToSplit}`);
+ const tx = api.tx.balances.transfer(newUser.address, amount);
+ txs.push(submitTransactionAsync(accounts[i], tx).catch(() => {
+ failedAccounts.push(i + usersWithBalance);
+ increaseCounter('txFailed', 1);
+ }));
+ increaseCounter('tx', 1);
}
+ await Promise.all(txs);
+ }
- for (let account of failedAccounts.reverse()) {
- accounts.splice(account, 1);
- }
- return accounts;
+ for (const account of failedAccounts.reverse()) {
+ accounts.splice(account, 1);
+ }
+ return accounts;
}
if (cluster.isMaster) {
- let testDone = false;
- usingApi(async (api) => {
- let prevCounters: { [key: string]: number } = {};
- while (!testDone) {
- for (let name in counters) {
- if (!(name in prevCounters)) {
- prevCounters[name] = 0;
- }
- if(counters[name] === prevCounters[name]) {
- continue;
- }
- console.log(`${name.padEnd(15)} = ${counters[name] - prevCounters[name]}`);
- prevCounters[name] = counters[name];
- }
- await waitNewBlocks(api, 1);
+ let testDone = false;
+ usingApi(async (api) => {
+ const prevCounters: { [key: string]: number } = {};
+ while (!testDone) {
+ for (const name in counters) {
+ if (!(name in prevCounters)) {
+ prevCounters[name] = 0;
+ }
+ if(counters[name] === prevCounters[name]) {
+ continue;
}
- });
- let waiting: Promise<void>[] = [];
- console.log(`Starting ${os.cpus().length} workers`);
- usingApi(async (api) => {
- const alice = privateKey('//Alice');
- for (let id in os.cpus()) {
- const WORKER_NAME = `//LoadWorker${id}_${Date.now()}`;
- const workerAccount = privateKey(WORKER_NAME);
- const tx = api.tx.balances.transfer(workerAccount.address, 400n * 10n ** 23n);
- await submitTransactionAsync(alice, tx);
+ console.log(`${name.padEnd(15)} = ${counters[name] - prevCounters[name]}`);
+ prevCounters[name] = counters[name];
+ }
+ await waitNewBlocks(api, 1);
+ }
+ });
+ const waiting: Promise<void>[] = [];
+ console.log(`Starting ${os.cpus().length} workers`);
+ usingApi(async (api) => {
+ const alice = privateKey('//Alice');
+ for (const id in os.cpus()) {
+ const WORKER_NAME = `//LoadWorker${id}_${Date.now()}`;
+ const workerAccount = privateKey(WORKER_NAME);
+ const tx = api.tx.balances.transfer(workerAccount.address, 400n * 10n ** 23n);
+ await submitTransactionAsync(alice, tx);
- let worker = cluster.fork({
- WORKER_NAME,
- STAGES: id + 2
- });
- worker.on('message', msg => {
- for (let key in msg) {
- increaseCounter(key, msg[key]);
- }
- });
- waiting.push(new Promise(res => worker.on('exit', res)));
+ const worker = cluster.fork({
+ WORKER_NAME,
+ STAGES: id + 2,
+ });
+ worker.on('message', msg => {
+ for (const key in msg) {
+ increaseCounter(key, msg[key]);
}
- await Promise.all(waiting);
- testDone = true;
- })
+ });
+ waiting.push(new Promise(res => worker.on('exit', res)));
+ }
+ await Promise.all(waiting);
+ testDone = true;
+ });
} else {
- increaseCounter('startedWorkers', 1);
- usingApi(async (api) => {
- await distributeBalance(privateKey(process.env.WORKER_NAME as string), api, 400n * 10n ** 22n, 10);
- });
- const interval = setInterval(() => {
- flushCounterToMaster();
- }, 100);
- interval.unref();
+ increaseCounter('startedWorkers', 1);
+ usingApi(async (api) => {
+ await distributeBalance(privateKey(process.env.WORKER_NAME as string), api, 400n * 10n ** 22n, 10);
+ });
+ const interval = setInterval(() => {
+ flushCounterToMaster();
+ }, 100);
+ interval.unref();
}
\ No newline at end of file
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -64,7 +64,7 @@
});
it('User can transfer owned token', async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
const Alice = privateKey('//Alice');
const Bob = privateKey('//Bob');
// nft
@@ -77,17 +77,23 @@
await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await transferExpectSuccess(reFungibleCollectionId,
- newReFungibleTokenId, Alice, Bob, 100, 'ReFungible');
+ await transferExpectSuccess(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Alice,
+ Bob,
+ 100,
+ 'ReFungible',
+ );
});
});
});
describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
before(async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
Charlie = privateKey('//Charlie');
@@ -119,11 +125,17 @@
await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await destroyCollectionExpectSuccess(reFungibleCollectionId);
- await transferExpectFail(reFungibleCollectionId,
- newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ await transferExpectFail(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Alice,
+ Bob,
+ 1,
+ 'ReFungible',
+ );
});
it('Transfer with not existed item_id', async () => {
// nft
@@ -134,9 +146,15 @@
await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- await transferExpectFail(reFungibleCollectionId,
- 2, Alice, Bob, 1, 'ReFungible');
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ await transferExpectFail(
+ reFungibleCollectionId,
+ 2,
+ Alice,
+ Bob,
+ 1,
+ 'ReFungible',
+ );
});
it('Transfer with deleted item_id', async () => {
// nft
@@ -151,11 +169,17 @@
await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
- await transferExpectFail(reFungibleCollectionId,
- newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ await transferExpectFail(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Alice,
+ Bob,
+ 1,
+ 'ReFungible',
+ );
});
it('Transfer with recipient that is not owner', async () => {
// nft
@@ -168,9 +192,15 @@
await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await transferExpectFail(reFungibleCollectionId,
- newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');
+ await transferExpectFail(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Charlie,
+ Bob,
+ 1,
+ 'ReFungible',
+ );
});
});
tests/src/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -14,7 +14,6 @@
createCollectionExpectSuccess,
createFungibleItemExpectSuccess,
createItemExpectSuccess,
- destroyCollectionExpectSuccess,
getAllowance,
transferFromExpectFail,
transferFromExpectSuccess,
@@ -31,7 +30,7 @@
let Charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
Charlie = privateKey('//Charlie');
@@ -39,7 +38,7 @@
});
it('Execute the extrinsic and check nftItemList - owner of token', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -52,13 +51,21 @@
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');
+
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);
- await transferFromExpectSuccess(reFungibleCollectionId,
- newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');
+ await transferFromExpectSuccess(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Bob,
+ Alice,
+ Charlie,
+ 100,
+ 'ReFungible',
+ );
});
});
@@ -92,7 +99,7 @@
let Charlie: IKeyringPair;
before(async () => {
- await usingApi(async (api) => {
+ await usingApi(async () => {
Alice = privateKey('//Alice');
Bob = privateKey('//Bob');
Charlie = privateKey('//Charlie');
@@ -139,7 +146,7 @@
}); */
it('transferFrom for not approved address', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -152,15 +159,21 @@
await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await transferFromExpectFail(reFungibleCollectionId,
- newReFungibleTokenId, Bob, Alice, Charlie, 1);
+ await transferFromExpectFail(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Bob,
+ Alice,
+ Charlie,
+ 1,
+ );
});
});
it('transferFrom incorrect token count', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -175,16 +188,22 @@
await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
- await transferFromExpectFail(reFungibleCollectionId,
- newReFungibleTokenId, Bob, Alice, Charlie, 2);
+ await transferFromExpectFail(
+ reFungibleCollectionId,
+ newReFungibleTokenId,
+ Bob,
+ Alice,
+ Charlie,
+ 2,
+ );
});
});
it('execute transferFrom from account that is not owner of collection', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const Dave = privateKey('//Dave');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
@@ -211,7 +230,7 @@
}
// reFungible
const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
+ createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
try {
await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);
@@ -223,7 +242,7 @@
});
});
it( 'transferFrom burnt token before approve NFT', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -233,7 +252,7 @@
});
});
it( 'transferFrom burnt token before approve Fungible', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
@@ -243,7 +262,7 @@
});
});
it( 'transferFrom burnt token before approve ReFungible', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
@@ -254,7 +273,7 @@
});
it( 'transferFrom burnt token after approve NFT', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
@@ -264,7 +283,7 @@
});
});
it( 'transferFrom burnt token after approve Fungible', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
@@ -274,7 +293,7 @@
});
});
it( 'transferFrom burnt token after approve ReFungible', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async () => {
const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
tests/src/util/contracthelpers.tsdiffbeforeafterboth--- a/tests/src/util/contracthelpers.ts
+++ b/tests/src/util/contracthelpers.ts
@@ -3,13 +3,13 @@
// file 'LICENSE', which is part of this source code package.
//
-import chai from "chai";
+import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";
-import fs from "fs";
-import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";
-import { IKeyringPair } from "@polkadot/types/types";
-import { ApiPromise, Keyring } from "@polkadot/api";
+import { submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
+import fs from 'fs';
+import { Abi, CodePromise, ContractPromise as Contract } from '@polkadot/api-contract';
+import { IKeyringPair } from '@polkadot/types/types';
+import { ApiPromise, Keyring } from '@polkadot/api';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -20,8 +20,9 @@
const gasLimit = '200000000000';
const endowment = '100000000000000000';
-function deployContract(alice: IKeyringPair, code: CodePromise, constructor: string = 'default', ...args: any[]): Promise<Contract> {
- return new Promise<Contract>(async (resolve, reject) => {
+/* eslint no-async-promise-executor: "off" */
+function deployContract(alice: IKeyringPair, code: CodePromise, constructor = 'default', ...args: any[]): Promise<Contract> {
+ return new Promise<Contract>(async (resolve) => {
const unsub = await (code as any)
.tx[constructor]({value: endowment, gasLimit}, ...args)
.signAndSend(alice, (result: any) => {
@@ -30,7 +31,7 @@
resolve((result as any).contract);
unsub();
}
- })
+ });
});
}
@@ -40,7 +41,7 @@
// Transfer balance to it
const keyring = new Keyring({ type: 'sr25519' });
- const alice = keyring.addFromUri(`//Alice`);
+ const alice = keyring.addFromUri('//Alice');
let amount = new BigNumber(endowment);
amount = amount.plus(100e15);
const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());
@@ -71,7 +72,7 @@
const result = await contract.query.get(deployer.address, value, gasLimit);
if(!result.result.isOk) {
- throw `Failed to get flipper value`;
+ throw 'Failed to get flipper value';
}
return (result.result.asOk.data[0] == 0x00) ? false : true;
}
@@ -87,19 +88,6 @@
export async function toggleFlipValueExpectFailure(sender: IKeyringPair, contract: Contract) {
const tx = contract.tx.flip(value, gasLimit);
await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
-}
-
-function instantiateTransferContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {
- return new Promise<any>(async (resolve, reject) => {
- const unsub = await blueprint.tx
- .default(endowment, gasLimit)
- .signAndSend(alice, (result) => {
- if (result.status.isInBlock || result.status.isFinalized) {
- unsub();
- resolve(result);
- }
- });
- });
}
export async function deployTransferContract(api: ApiPromise): Promise<[Contract, IKeyringPair]> {
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -4,22 +4,18 @@
//
import { ApiPromise, Keyring } from '@polkadot/api';
-import { Enum, Struct } from '@polkadot/types/codec';
-import type { AccountId, BlockNumber, Call, EventRecord } from '@polkadot/types/interfaces';
-import { u128 } from '@polkadot/types/primitive';
+import type { AccountId, EventRecord } from '@polkadot/types/interfaces';
import { IKeyringPair } from '@polkadot/types/types';
import { evmToAddress } from '@polkadot/util-crypto';
import { BigNumber } from 'bignumber.js';
import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import { alicesPublicKey, nullPublicKey } from '../accounts';
+import { alicesPublicKey } from '../accounts';
import privateKey from '../substrate/privateKey';
import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
import { ICollectionInterface } from '../types';
import { hexToStr, strToUTF16, utf16ToStr } from './util';
-import { Compact, Option, Raw, Vec } from '@polkadot/types/codec';
-// import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicSignatureV1, ExtrinsicSignatureV2, ExtrinsicSignatureV3, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, Moment, MortalEra, MultiSignature, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -85,10 +81,6 @@
Owner: number[];
ConstData: number[];
VariableData: number[];
-}
-
-interface IFungibleTokenDataType {
- Value: BN;
}
interface IGetMessage {
@@ -104,9 +96,9 @@
}
export function nftEventMessage(events: EventRecord[]): IGetMessage {
- let checkMsgNftMethod: string = '';
- let checkMsgTrsMethod: string = '';
- let checkMsgSysMethod: string = '';
+ let checkMsgNftMethod = '';
+ let checkMsgTrsMethod = '';
+ let checkMsgSysMethod = '';
events.forEach(({ event: { method, section } }) => {
if (section === 'nft') {
checkMsgNftMethod = method;
@@ -128,7 +120,7 @@
const result: GenericResult = {
success: false,
};
- events.forEach(({ phase, event: { data, method, section } }) => {
+ events.forEach(({ event: { method } }) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method === 'ExtrinsicSuccess') {
result.success = true;
@@ -141,8 +133,8 @@
export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {
let success = false;
- let collectionId: number = 0;
- events.forEach(({ phase, event: { data, method, section } }) => {
+ let collectionId = 0;
+ events.forEach(({ event: { data, method, section } }) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method == 'ExtrinsicSuccess') {
success = true;
@@ -159,10 +151,10 @@
export function getCreateItemResult(events: EventRecord[]): CreateItemResult {
let success = false;
- let collectionId: number = 0;
- let itemId: number = 0;
+ let collectionId = 0;
+ let itemId = 0;
let recipient;
- events.forEach(({ phase, event: { data, method, section } }) => {
+ events.forEach(({ event: { data, method, section } }) => {
// console.log(` ${phase}: ${section}.${method}:: ${data}`);
if (method == 'ExtrinsicSuccess') {
success = true;
@@ -235,12 +227,12 @@
mode: { type: 'NFT' },
name: 'name',
tokenPrefix: 'prefix',
-}
+};
export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
const { name, description, mode, tokenPrefix } = { ...defaultCreateCollectionParams, ...params };
- let collectionId: number = 0;
+ let collectionId = 0;
await usingApi(async (api) => {
// Get number of collections before the transaction
const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
@@ -351,9 +343,8 @@
}
function getDestroyResult(events: EventRecord[]): boolean {
- let success: boolean = false;
- events.forEach(({ phase, event: { data, method, section } }) => {
- // console.log(` ${phase}: ${section}.${method}:: ${data}`);
+ let success = false;
+ events.forEach(({ event: { method } }) => {
if (method == 'ExtrinsicSuccess') {
success = true;
}
@@ -361,7 +352,7 @@
return success;
}
-export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
+export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {
await usingApi(async (api) => {
// Run the DestroyCollection transaction
const alicePrivateKey = privateKey(senderSeed);
@@ -370,7 +361,7 @@
});
}
-export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {
await usingApi(async (api) => {
// Run the DestroyCollection transaction
const alicePrivateKey = privateKey(senderSeed);
@@ -465,7 +456,7 @@
});
}
-export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {
+export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
@@ -475,7 +466,7 @@
});
}
-export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
@@ -496,7 +487,7 @@
}
-export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
+export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
@@ -546,7 +537,7 @@
});
}
-export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enabled: boolean) {
+export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string) {
await usingApi(async (api) => {
const tx = api.tx.nft.toggleContractWhiteList(contractAddress, true);
const events = await submitTransactionAsync(sender, tx);
@@ -557,7 +548,7 @@
}
export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) {
- let whitelisted: boolean = false;
+ let whitelisted = false;
await usingApi(async (api) => {
whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean;
});
@@ -659,8 +650,10 @@
}
export async function
- approveExpectSuccess(collectionId: number,
- tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1) {
+approveExpectSuccess(
+ collectionId: number,
+ tokenId: number, owner: IKeyringPair, approved: IKeyringPair | CrossAccountId | string, amount: number | bigint = 1,
+) {
await usingApi(async (api: ApiPromise) => {
approved = normalizeAccountId(approved);
const allowanceBefore =
@@ -677,21 +670,22 @@
}
export async function
- transferFromExpectSuccess(collectionId: number,
- tokenId: number,
- accountApproved: IKeyringPair,
- accountFrom: IKeyringPair | CrossAccountId,
- accountTo: IKeyringPair | CrossAccountId,
- value: number | bigint = 1,
- type: string = 'NFT') {
+transferFromExpectSuccess(
+ collectionId: number,
+ tokenId: number,
+ accountApproved: IKeyringPair,
+ accountFrom: IKeyringPair | CrossAccountId,
+ accountTo: IKeyringPair | CrossAccountId,
+ value: number | bigint = 1,
+ type = 'NFT',
+) {
await usingApi(async (api: ApiPromise) => {
const to = normalizeAccountId(accountTo);
let balanceBefore = new BN(0);
if (type === 'Fungible') {
balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;
}
- const transferFromTx = api.tx.nft.transferFrom(
- normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
+ const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
const events = await submitTransactionAsync(accountApproved, transferFromTx);
const result = getCreateItemResult(events);
// tslint:disable-next-line:no-unused-expression
@@ -714,15 +708,16 @@
}
export async function
- transferFromExpectFail(collectionId: number,
- tokenId: number,
- accountApproved: IKeyringPair,
- accountFrom: IKeyringPair,
- accountTo: IKeyringPair,
- value: number | bigint = 1) {
+transferFromExpectFail(
+ collectionId: number,
+ tokenId: number,
+ accountApproved: IKeyringPair,
+ accountFrom: IKeyringPair,
+ accountTo: IKeyringPair,
+ value: number | bigint = 1,
+) {
await usingApi(async (api: ApiPromise) => {
- const transferFromTx = api.tx.nft.transferFrom(
- normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);
+ const transferFromTx = api.tx.nft.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);
const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;
const result = getCreateCollectionResult(events);
// tslint:disable-next-line:no-unused-expression
@@ -730,36 +725,34 @@
});
}
+/* eslint no-async-promise-executor: "off" */
async function getBlockNumber(api: ApiPromise): Promise<number> {
- return new Promise<number>(async (resolve, reject) => {
+ return new Promise<number>(async (resolve) => {
const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {
- unsubscribe();
- resolve(head.number.toNumber());
+ unsubscribe();
+ resolve(head.number.toNumber());
});
});
}
export async function
-scheduleTransferExpectSuccess(collectionId: number,
- tokenId: number,
- sender: IKeyringPair,
- recipient: IKeyringPair,
- value: number | bigint = 1,
- type: string = 'NFT') {
+scheduleTransferExpectSuccess(
+ collectionId: number,
+ tokenId: number,
+ sender: IKeyringPair,
+ recipient: IKeyringPair,
+ value: number | bigint = 1,
+) {
await usingApi(async (api: ApiPromise) => {
- let balanceBefore = new BN(0);
-
-
- let blockNumber: number | undefined = await getBlockNumber(api);
- let expectedBlockNumber = blockNumber + 2;
+ const blockNumber: number | undefined = await getBlockNumber(api);
+ const expectedBlockNumber = blockNumber + 2;
expect(blockNumber).to.be.greaterThan(0);
const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
- const events = await submitTransactionAsync(sender, scheduleTx);
+ await submitTransactionAsync(sender, scheduleTx);
- const sponsorBalanceBefore = new BigNumber((await api.query.system.account(sender.address)).data.free.toString());
const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
@@ -768,7 +761,6 @@
// sleep for 2 blocks
await new Promise(resolve => setTimeout(resolve, 6000 * 2));
- const sponsorBalanceAfter = new BigNumber((await api.query.system.account(sender.address)).data.free.toString());
const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
@@ -779,12 +771,14 @@
export async function
- transferExpectSuccess(collectionId: number,
- tokenId: number,
- sender: IKeyringPair,
- recipient: IKeyringPair | CrossAccountId,
- value: number | bigint = 1,
- type: string = 'NFT') {
+transferExpectSuccess(
+ collectionId: number,
+ tokenId: number,
+ sender: IKeyringPair,
+ recipient: IKeyringPair | CrossAccountId,
+ value: number | bigint = 1,
+ type = 'NFT',
+) {
await usingApi(async (api: ApiPromise) => {
const to = normalizeAccountId(recipient);
@@ -820,12 +814,13 @@
}
export async function
- transferExpectFail(collectionId: number,
- tokenId: number,
- sender: IKeyringPair,
- recipient: IKeyringPair,
- value: number | bigint = 1,
- type: string = 'NFT') {
+transferExpectFail(
+ collectionId: number,
+ tokenId: number,
+ sender: IKeyringPair,
+ recipient: IKeyringPair,
+ value: number | bigint = 1,
+) {
await usingApi(async (api: ApiPromise) => {
const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;
@@ -838,8 +833,10 @@
}
export async function
- approveExpectFail(collectionId: number,
- tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1) {
+approveExpectFail(
+ collectionId: number,
+ tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,
+) {
await usingApi(async (api: ApiPromise) => {
const approveNftTx = api.tx.nft.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);
const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;
@@ -876,9 +873,8 @@
});
}
-export async function createItemExpectSuccess(
- sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
- let newItemId: number = 0;
+export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
+ let newItemId = 0;
await usingApi(async (api) => {
const to = normalizeAccountId(owner);
const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
@@ -919,8 +915,7 @@
return newItemId;
}
-export async function createItemExpectFailure(
- sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {
+export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {
await usingApi(async (api) => {
const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);
@@ -994,7 +989,7 @@
}
export async function isWhitelisted(collectionId: number, address: string) {
- let whitelisted: boolean = false;
+ let whitelisted = false;
await usingApi(async (api) => {
whitelisted = (await api.query.nft.whiteList(collectionId, address)).toJSON() as unknown as boolean;
});
tests/src/util/util.tsdiffbeforeafterboth--- a/tests/src/util/util.ts
+++ b/tests/src/util/util.ts
@@ -4,7 +4,7 @@
//
export function strToUTF16(str: string): any {
- let buf: number[] = [];
+ const buf: number[] = [];
for (let i=0, strLen=str.length; i < strLen; i++) {
buf.push(str.charCodeAt(i));
}
@@ -12,7 +12,7 @@
}
export function utf16ToStr(buf: number[]): string {
- let str: string = "";
+ let str = '';
for (let i=0, strLen=buf.length; i < strLen; i++) {
if (buf[i] != 0) str += String.fromCharCode(buf[i]);
else break;
@@ -21,13 +21,13 @@
}
export function hexToStr(buf: string): string {
- let str: string = "";
- let hexStart = buf.indexOf("0x");
+ let str = '';
+ let hexStart = buf.indexOf('0x');
if (hexStart < 0) hexStart = 0;
else hexStart = 2;
for (let i=hexStart, strLen=buf.length; i < strLen; i+=2) {
- let ch = buf[i] + buf[i+1];
- let num = parseInt(ch, 16);
+ const ch = buf[i] + buf[i+1];
+ const num = parseInt(ch, 16);
if (num != 0) str += String.fromCharCode(num);
else break;
}