difftreelog
Add test events
in: master
Add NFTPAR-321,325,326,324,347,345
8 files changed
tests/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);
+ });
+ });
+});
+
tests/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
tests/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);
+ });
+ });
+});
+
tests/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);
+ });
+ });
+});
+
tests/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);
+ });
+ });
+});
+
tests/src/check-event/transferEvent.test.tsdiffbeforeafterbothno changes
tests/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);
+ });
+ });
+});
+
tests/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;