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
--- 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",
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
18import '../interfaces/augment-api-query';18import '../interfaces/augment-api-query';
19import {ApiPromise, Keyring} from '@polkadot/api';19import {ApiPromise, Keyring} from '@polkadot/api';
20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';
21import type {GenericEventData} from '@polkadot/types';
21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';22import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';
22import {evmToAddress} from '@polkadot/util-crypto';23import {evmToAddress} from '@polkadot/util-crypto';
23import BN from 'bn.js';24import BN from 'bn.js';
88const CENTIUNIQUE = 10n * MILLIUNIQUE;89const CENTIUNIQUE = 10n * MILLIUNIQUE;
89export const UNIQUE = 100n * CENTIUNIQUE;90export const UNIQUE = 100n * CENTIUNIQUE;
9091
91type GenericResult = {92interface GenericResult<T> {
92 success: boolean,93 success: boolean;
94 data: T | null;
93};95}
9496
95interface CreateCollectionResult {97interface CreateCollectionResult {
96 success: boolean;98 success: boolean;
170 return event.event as T;172 return event.event as T;
171}173}
172174
173export function getGenericResult(events: EventRecord[]): GenericResult {175export function getGenericResult<T>(
176 events: EventRecord[],
177 expectSection?: string,
178 expectMethod?: string,
179 extractAction?: (data: GenericEventData) => T,
180): GenericResult<T> {
174 const result: GenericResult = {181 let success = false;
175 success: false,182 let successData = null;
176 };
177 events.forEach(({event: {method}}) => {183 events.forEach(({event: {data, method, section}}) => {
178 // console.log(` ${phase}: ${section}.${method}:: ${data}`);
179 if (method === 'ExtrinsicSuccess') {184 if (method === 'ExtrinsicSuccess') {
180 result.success = true;185 success = true;
181 }186 } else if ((expectSection == section) && (expectMethod == method)) {
187 successData = extractAction!(data);
188 }
182 });189 });
190 const result: GenericResult<T> = {
191 success,
192 data: successData,
193 };
183 return result;194 return result;
184}195}
185