difftreelog
test(rmrk-proxy) sample externality test
in: master
3 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -37,6 +37,7 @@
"testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
"testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
+ "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
"testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
"testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
"testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
tests/src/rmrk/rmrk.test.tsdiffbeforeafterboth1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {5 getCreateCollectionResult,6 getDetailedCollectionInfo,7 getGenericResult,8} from '../util/helpers';9import {IKeyringPair} from '@polkadot/types/types';1011let alice: IKeyringPair;12let bob: IKeyringPair;1314describe('RMRK External Integration Test', () => {15 before(async () => {16 await usingApi(async () => {17 alice = privateKey('//Alice');18 bob = privateKey('//Bob');19 });20 });2122 it('Creates a new RMRK collection that is tagged as external', async () => {23 await usingApi(async api => {24 const tx = api.tx.rmrkCore.createCollection('no-limit-metadata', null, 'no-limit-symbol');25 const events = await executeTransaction(api, alice, tx);26 const result = getCreateCollectionResult(events);2728 const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;29 expect(collection.readOnly.toHuman()).to.be.true;30 });31 });3233 it('[Negative] Forbids NFT operations with an external collection', async () => {34 await usingApi(async api => {35 const tx1 = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');36 const events1 = await executeTransaction(api, alice, tx1);3738 const resultUnique1 = getCreateCollectionResult(events1);39 const uniqueCollectionId = resultUnique1.collectionId;4041 const resultRmrk1 = getGenericResult(events1, 'rmrkCore', 'CollectionCreated', (data) => {42 return parseInt(data[1].toString(), 10);43 });44 const rmrkCollectionId: number = resultRmrk1.data!;4546 const tx2 = api.tx.rmrkCore.mintNft(47 alice.address,48 rmrkCollectionId,49 alice.address,50 null,51 'nft-metadata',52 true,53 );54 const events2 = await executeTransaction(api, alice, tx2);55 const result2 = getGenericResult(events2, 'rmrkCore', 'NftMinted', (data) => {56 return parseInt(data[2].toString(), 10);57 });58 const rmrkNftId: number = result2.data!;5960 const tx3 = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);61 await expect(executeTransaction(api, alice, tx3)).to.be.rejectedWith(/common\.CollectionIsExternal/);62 });63 });64});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -18,6 +18,7 @@
import '../interfaces/augment-api-query';
import {ApiPromise, Keyring} from '@polkadot/api';
import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';
+import type {GenericEventData} from '@polkadot/types';
import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';
import {evmToAddress} from '@polkadot/util-crypto';
import BN from 'bn.js';
@@ -88,9 +89,10 @@
const CENTIUNIQUE = 10n * MILLIUNIQUE;
export const UNIQUE = 100n * CENTIUNIQUE;
-type GenericResult = {
- success: boolean,
-};
+interface GenericResult<T> {
+ success: boolean;
+ data: T | null;
+}
interface CreateCollectionResult {
success: boolean;
@@ -170,20 +172,27 @@
return event.event as T;
}
-export function getGenericResult(events: EventRecord[]): GenericResult {
- const result: GenericResult = {
- success: false,
- };
- events.forEach(({event: {method}}) => {
- // console.log(` ${phase}: ${section}.${method}:: ${data}`);
+export function getGenericResult<T>(
+ events: EventRecord[],
+ expectSection?: string,
+ expectMethod?: string,
+ extractAction?: (data: GenericEventData) => T,
+): GenericResult<T> {
+ let success = false;
+ let successData = null;
+ events.forEach(({event: {data, method, section}}) => {
if (method === 'ExtrinsicSuccess') {
- result.success = true;
+ success = true;
+ } else if ((expectSection == section) && (expectMethod == method)) {
+ successData = extractAction!(data);
}
});
+ const result: GenericResult<T> = {
+ success,
+ data: successData,
+ };
return result;
}
-
-
export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {
let success = false;