git.delta.rocks / unique-network / refs/commits / 81a57542f2f2

difftreelog

test(rmrk-proxy) sample externality test

Fahrrader2022-06-08parent: #719aab2.patch.diff
in: master

3 files changed

modifiedtests/package.jsondiffbeforeafterboth
37 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",37 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
38 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",38 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
39 "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",39 "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
40 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
40 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",41 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
41 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",42 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
42 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",43 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
addedtests/src/rmrk/rmrk.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/rmrk/rmrk.test.ts
@@ -0,0 +1,64 @@
+import {expect} from 'chai';
+import privateKey from '../substrate/privateKey';
+import usingApi, {executeTransaction} from '../substrate/substrate-api';
+import {
+  getCreateCollectionResult,
+  getDetailedCollectionInfo,
+  getGenericResult,
+} from '../util/helpers';
+import {IKeyringPair} from '@polkadot/types/types';
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+
+describe('RMRK External Integration Test', () => {
+  before(async () => {
+    await usingApi(async () => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+    });
+  });
+
+  it('Creates a new RMRK collection that is tagged as external', async () => {
+    await usingApi(async api => {
+      const tx = api.tx.rmrkCore.createCollection('no-limit-metadata', null, 'no-limit-symbol');
+      const events = await executeTransaction(api, alice, tx);
+      const result = getCreateCollectionResult(events);
+
+      const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;
+      expect(collection.readOnly.toHuman()).to.be.true;
+    });
+  });
+
+  it('[Negative] Forbids NFT operations with an external collection', async () => {
+    await usingApi(async api => {
+      const tx1 = api.tx.rmrkCore.createCollection('metadata', null, 'symbol');
+      const events1 = await executeTransaction(api, alice, tx1);
+
+      const resultUnique1 = getCreateCollectionResult(events1);
+      const uniqueCollectionId = resultUnique1.collectionId;
+
+      const resultRmrk1 = getGenericResult(events1, 'rmrkCore', 'CollectionCreated', (data) => {
+        return parseInt(data[1].toString(), 10);
+      });
+      const rmrkCollectionId: number = resultRmrk1.data!;
+
+      const tx2 = api.tx.rmrkCore.mintNft(
+        alice.address,
+        rmrkCollectionId,
+        alice.address,
+        null,
+        'nft-metadata',
+        true,
+      );
+      const events2 = await executeTransaction(api, alice, tx2);
+      const result2 = getGenericResult(events2, 'rmrkCore', 'NftMinted', (data) => {
+        return parseInt(data[2].toString(), 10);
+      });
+      const rmrkNftId: number = result2.data!;
+
+      const tx3 = api.tx.unique.burnItem(uniqueCollectionId, rmrkNftId, 1);
+      await expect(executeTransaction(api, alice, tx3)).to.be.rejectedWith(/common\.CollectionIsExternal/);
+    });
+  });
+});
\ No newline at end of file
modifiedtests/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;