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

no changes

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
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -63,12 +63,39 @@
   Value: BN;
 }
 
+interface IGetMessage {
+  checkMsgNftMethod: string;
+  checkMsgTrsMethod: string;
+  checkMsgSysMethod: string;
+}
+
 export interface IReFungibleTokenDataType {
   Owner: IReFungibleOwner[];
   ConstData: number[];
   VariableData: number[];
 }
 
+export function nftEventMessage(events: EventRecord[]): IGetMessage {
+  let checkMsgNftMethod: string = '';
+  let checkMsgTrsMethod: string = '';
+  let checkMsgSysMethod: string = '';
+  events.forEach(({ event: { method, section } }) => {
+    if (section === 'nft') {
+      checkMsgNftMethod = method;
+    } else if (section === 'treasury') {
+      checkMsgTrsMethod = method;
+    } else if (section === 'system') {
+      checkMsgSysMethod = method;
+    } else { return null; }
+  });
+  const result: IGetMessage = {
+    checkMsgNftMethod,
+    checkMsgTrsMethod,
+    checkMsgSysMethod,
+  };
+  return result;
+}
+
 export function getGenericResult(events: EventRecord[]): GenericResult {
   const result: GenericResult = {
     success: false,
@@ -82,6 +109,8 @@
   return result;
 }
 
+
+
 export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {
   let success = false;
   let collectionId: number = 0;