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

difftreelog

Add test events

Antz0x0z2021-03-06parent: #1f47f96.patch.diff
in: master
Add NFTPAR-321,325,326,324,347,345

8 files changed

addedtests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -0,0 +1,41 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Burn Item event ', () => {
+  let Alice: IKeyringPair;
+  const checkSection = 'ItemDestroyed';
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+    });
+  });
+  it('Check event from burnItem(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
+      const burnItem = api.tx.nft.burnItem(collectionID, itemID, 1);
+      const events = await submitTransactionAsync(Alice, burnItem);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkSection);
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
addedtests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/createCollectionEvent.test.ts
@@ -0,0 +1,39 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Create collection event ', () => {
+  let Alice: IKeyringPair;
+  const checkSection = 'Created';
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+    });
+  });
+  it('Check event from createCollection(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const tx = api.tx.nft.createCollection('0x31', '0x32', '0x33', 'NFT');
+      const events = await submitTransactionAsync(Alice, tx);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkSection);
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+ 
\ No newline at end of file
addedtests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/createItemEvent.test.ts
@@ -0,0 +1,40 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Create Item event ', () => {
+  let Alice: IKeyringPair;
+  const checkSection = 'ItemCreated';
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+    });
+  });
+  it('Check event from createItem(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const createItem = api.tx.nft.createItem(collectionID, Alice.address, 'NFT');
+      const events = await submitTransactionAsync(Alice, createItem);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkSection);
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
addedtests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -0,0 +1,41 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Create Multiple Items Event event ', () => {
+  let Alice: IKeyringPair;
+  const checkSection = 'ItemCreated (x3)';
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+    });
+  });
+  it('Check event from createMultipleItems(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
+      const createMultipleItems = api.tx.nft.createMultipleItems(collectionID, Alice.address, args);
+      const events = await submitTransactionAsync(Alice, createMultipleItems);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkSection);
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
addedtests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/destroyCollectionEvent.test.ts
@@ -0,0 +1,38 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Destroy collection event ', () => {
+  let Alice: IKeyringPair;
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+    });
+  });
+  it('Check event from destroyCollection(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const destroyCollection = api.tx.nft.destroyCollection(collectionID);
+      const events = await submitTransactionAsync(Alice, destroyCollection);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
addedtests/src/check-event/transferEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/transferEvent.test.ts
@@ -0,0 +1,42 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Transfer event ', () => {
+  let Alice: IKeyringPair;
+  let Bob: IKeyringPair;
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+      Bob = privateKey('//Bob');
+    });
+  });
+  it('Check event from transfer(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
+      const transfer = api.tx.nft.transfer(Bob.address, collectionID, itemID, 1);
+      const events = await submitTransactionAsync(Alice, transfer);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
+
addedtests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/check-event/transferFromEvent.test.ts
@@ -0,0 +1,41 @@
+//
+// 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#setchainlimits
+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, {submitTransactionAsync} from '../substrate/substrate-api';
+import { createCollectionExpectSuccess, createItemExpectSuccess, nftEventMessage } from '../util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Transfer from event ', () => {
+  let Alice: IKeyringPair;
+  let Bob: IKeyringPair;
+  const checkTreasury = 'Deposit';
+  const checkSystem = 'ExtrinsicSuccess';
+  before(async () => {
+    await usingApi(async () => {
+      Alice = privateKey('//Alice');
+      Bob = privateKey('//Bob');
+    });
+  });
+  it('Check event from transferFrom(): ', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const collectionID = await createCollectionExpectSuccess();
+      const itemID = await createItemExpectSuccess(Alice, collectionID, 'NFT');
+      const transferFrom = api.tx.nft.transferFrom(Alice.address, Bob.address, collectionID, itemID, 1);
+      const events = await submitTransactionAsync(Alice, transferFrom);
+      const msg = JSON.stringify(nftEventMessage(events));
+      expect(msg).to.be.contain(checkTreasury);
+      expect(msg).to.be.contain(checkSystem);
+    });
+  });
+});
+
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
63 Value: BN;63 Value: BN;
64}64}
65
66interface IGetMessage {
67 checkMsgNftMethod: string;
68 checkMsgTrsMethod: string;
69 checkMsgSysMethod: string;
70}
6571
66export interface IReFungibleTokenDataType {72export interface IReFungibleTokenDataType {
67 Owner: IReFungibleOwner[];73 Owner: IReFungibleOwner[];
68 ConstData: number[];74 ConstData: number[];
69 VariableData: number[];75 VariableData: number[];
70}76}
77
78export function nftEventMessage(events: EventRecord[]): IGetMessage {
79 let checkMsgNftMethod: string = '';
80 let checkMsgTrsMethod: string = '';
81 let checkMsgSysMethod: string = '';
82 events.forEach(({ event: { method, section } }) => {
83 if (section === 'nft') {
84 checkMsgNftMethod = method;
85 } else if (section === 'treasury') {
86 checkMsgTrsMethod = method;
87 } else if (section === 'system') {
88 checkMsgSysMethod = method;
89 } else { return null; }
90 });
91 const result: IGetMessage = {
92 checkMsgNftMethod,
93 checkMsgTrsMethod,
94 checkMsgSysMethod,
95 };
96 return result;
97}
7198
72export function getGenericResult(events: EventRecord[]): GenericResult {99export function getGenericResult(events: EventRecord[]): GenericResult {
73 const result: GenericResult = {100 const result: GenericResult = {