difftreelog
fix skip rmrk before
in: master
1 file changed
tests/src/rmrk/rmrkIsolation.test.tsdiffbeforeafterboth1import {executeTransaction} from '../substrate/substrate-api';2import {IKeyringPair} from '@polkadot/types/types';3import {itSub, expect, usingPlaygrounds, Pallets} from '../util/playgrounds';4import {UniqueHelper} from '../util/playgrounds/unique';56let alice: IKeyringPair;7let bob: IKeyringPair;89async function createRmrkCollection(helper: UniqueHelper, sender: IKeyringPair): Promise<{uniqueId: number, rmrkId: number}> {10 const result = await helper.executeExtrinsic(sender, 'api.tx.rmrkCore.createCollection', ['metadata', null, 'symbol'], true);1112 const uniqueId = helper.util.extractCollectionIdFromCreationResult(result);1314 let rmrkId = null;15 result.result.events.forEach(({event: {data, method, section}}) => {16 if ((section === 'rmrkCore') && (method === 'CollectionCreated')) {17 rmrkId = parseInt(data[1].toString(), 10);18 }19 });2021 if (rmrkId === null) {22 throw Error('No rmrkCore.CollectionCreated event was found!');23 }2425 return {26 uniqueId,27 rmrkId,28 };29}3031async function createRmrkNft(helper: UniqueHelper, sender: IKeyringPair, collectionId: number): Promise<number> {32 const result = await helper.executeExtrinsic(33 sender,34 'api.tx.rmrkCore.mintNft',35 [36 sender.address,37 collectionId,38 sender.address,39 null,40 'nft-metadata',41 true,42 null,43 ],44 true,45 );4647 let rmrkNftId = null;48 result.result.events.forEach(({event: {data, method, section}}) => {49 if ((section === 'rmrkCore') && (method === 'NftMinted')) {50 rmrkNftId = parseInt(data[2].toString(), 10);51 }52 });5354 if (rmrkNftId === null) {55 throw Error('No rmrkCore.NftMinted event was found!');56 }5758 return rmrkNftId;59}6061describe('RMRK External Integration Test', async () => {62 before(async function() {63 await usingPlaygrounds(async (_helper, privateKey) => {64 alice = privateKey('//Alice');65 });66 });6768 itSub.ifWithPallets('Creates a new RMRK collection that is mapped to a different ID and is tagged as external', [Pallets.RmrkCore], async ({helper}) => {69 // throw away collection to bump last Unique collection ID to test ID mapping70 await helper.nft.mintCollection(alice, {tokenPrefix: 'unqt'});7172 const collectionIds = await createRmrkCollection(helper, alice);7374 expect(collectionIds.rmrkId).to.be.lessThan(collectionIds.uniqueId, 'collection ID mapping');7576 const collection = (await helper.nft.getCollectionObject(collectionIds.uniqueId).getData())!; // (await getDetailedCollectionInfo(api, collectionIds.uniqueId))!;77 expect(collection.raw.readOnly, 'tagged external').to.be.true;78 });79});8081describe('Negative Integration Test: External Collections, Internal Ops', async () => {82 let uniqueCollectionId: number;83 let rmrkCollectionId: number;84 let rmrkNftId: number;85 let normalizedAlice: {Substrate: string};8687 before(async () => {88 await usingPlaygrounds(async (helper, privateKey) => {89 alice = privateKey('//Alice');90 bob = privateKey('//Bob');91 normalizedAlice = {Substrate: helper.address.normalizeSubstrateToChainFormat(alice.address)};9293 const collectionIds = await createRmrkCollection(helper, alice);94 uniqueCollectionId = collectionIds.uniqueId;95 rmrkCollectionId = collectionIds.rmrkId;9697 rmrkNftId = await createRmrkNft(helper, alice, rmrkCollectionId);98 });99 });100101 itSub.ifWithPallets('[Negative] Forbids Unique operations with an external collection, handled by dispatch_call', [Pallets.RmrkCore], async ({helper}) => {102 // Collection item creation103104 await expect(helper.nft.mintToken(alice, {collectionId: uniqueCollectionId, owner: {Substrate: alice.address}}), 'creating item')105 .to.be.rejectedWith(/common\.CollectionIsExternal/);106107 const txCreateMultipleItems = helper.getApi().tx.unique.createMultipleItems(uniqueCollectionId, normalizedAlice, [{NFT: {}}, {NFT: {}}]);108 await expect(executeTransaction(helper.getApi(), alice, txCreateMultipleItems), 'creating multiple')109 .to.be.rejectedWith(/common\.CollectionIsExternal/);110 111 await expect(helper.nft.mintMultipleTokens(alice, uniqueCollectionId, [{owner: {Substrate: alice.address}}]), 'creating multiple ex')112 .to.be.rejectedWith(/common\.CollectionIsExternal/);113114 // Collection properties115116 await expect(helper.nft.setProperties(alice, uniqueCollectionId, [{key: 'a', value: '1'}, {key: 'b'}]), 'setting collection properties')117 .to.be.rejectedWith(/common\.CollectionIsExternal/);118119 await expect(helper.nft.deleteProperties(alice, uniqueCollectionId, ['a']), 'deleting collection properties')120 .to.be.rejectedWith(/common\.CollectionIsExternal/);121122 await expect(helper.nft.setTokenPropertyPermissions(alice, uniqueCollectionId, [{key: 'a', permission: {mutable: true}}]), 'setting property permissions')123 .to.be.rejectedWith(/common\.CollectionIsExternal/);124125 // NFT126127 await expect(helper.nft.burnToken(alice, uniqueCollectionId, rmrkNftId, 1n), 'burning')128 .to.be.rejectedWith(/common\.CollectionIsExternal/);129130 await expect(helper.nft.burnTokenFrom(alice, uniqueCollectionId, rmrkNftId, {Substrate: alice.address}, 1n), 'burning-from')131 .to.be.rejectedWith(/common\.CollectionIsExternal/);132133 await expect(helper.nft.transferToken(alice, uniqueCollectionId, rmrkNftId, {Substrate: bob.address}), 'transferring')134 .to.be.rejectedWith(/common\.CollectionIsExternal/);135136 await expect(helper.nft.approveToken(alice, uniqueCollectionId, rmrkNftId, {Substrate: bob.address}), 'approving')137 .to.be.rejectedWith(/common\.CollectionIsExternal/);138139 await expect(helper.nft.transferTokenFrom(alice, uniqueCollectionId, rmrkNftId, {Substrate: alice.address}, {Substrate: bob.address}), 'transferring-from')140 .to.be.rejectedWith(/common\.CollectionIsExternal/);141142 // NFT properties143144 await expect(helper.nft.setTokenProperties(alice, uniqueCollectionId, rmrkNftId, [{key: 'a', value: '2'}]), 'setting token properties')145 .to.be.rejectedWith(/common\.CollectionIsExternal/);146147 await expect(helper.nft.deleteTokenProperties(alice, uniqueCollectionId, rmrkNftId, ['a']))148 .to.be.rejectedWith(/common\.CollectionIsExternal/);149 });150151 itSub.ifWithPallets('[Negative] Forbids Unique collection operations with an external collection', [Pallets.RmrkCore], async ({helper}) => {152 await expect(helper.nft.burn(alice, uniqueCollectionId), 'destroying collection')153 .to.be.rejectedWith(/common\.CollectionIsExternal/);154155 // Allow list156157 await expect(helper.nft.addToAllowList(alice, uniqueCollectionId, {Substrate: bob.address}), 'adding to allow list')158 .to.be.rejectedWith(/common\.CollectionIsExternal/);159160 await expect(helper.nft.removeFromAllowList(alice, uniqueCollectionId, {Substrate: bob.address}), 'removing from allowlist')161 .to.be.rejectedWith(/common\.CollectionIsExternal/);162163 // Owner / Admin / Sponsor164165 await expect(helper.nft.changeOwner(alice, uniqueCollectionId, bob.address), 'changing owner')166 .to.be.rejectedWith(/common\.CollectionIsExternal/);167168 await expect(helper.nft.addAdmin(alice, uniqueCollectionId, {Substrate: bob.address}), 'adding admin')169 .to.be.rejectedWith(/common\.CollectionIsExternal/);170171 await expect(helper.nft.removeAdmin(alice, uniqueCollectionId, {Substrate: bob.address}), 'removing admin')172 .to.be.rejectedWith(/common\.CollectionIsExternal/);173174 await expect(helper.nft.setSponsor(alice, uniqueCollectionId, bob.address), 'setting sponsor')175 .to.be.rejectedWith(/common\.CollectionIsExternal/);176177 await expect(helper.nft.confirmSponsorship(alice, uniqueCollectionId), 'confirming sponsor')178 .to.be.rejectedWith(/common\.CollectionIsExternal/);179180 await expect(helper.nft.removeSponsor(alice, uniqueCollectionId), 'removing sponsor')181 .to.be.rejectedWith(/common\.CollectionIsExternal/);182 183 // Limits / permissions / transfers184185 const txSetTransfers = helper.getApi().tx.unique.setTransfersEnabledFlag(uniqueCollectionId, true);186 await expect(executeTransaction(helper.getApi(), alice, txSetTransfers), 'setting transfers enabled flag')187 .to.be.rejectedWith(/common\.CollectionIsExternal/);188189 await expect(helper.nft.setLimits(alice, uniqueCollectionId, {transfersEnabled: false}), 'setting collection limits')190 .to.be.rejectedWith(/common\.CollectionIsExternal/);191192 await expect(helper.nft.setPermissions(alice, uniqueCollectionId, {access: 'AllowList'}), 'setting collection permissions')193 .to.be.rejectedWith(/common\.CollectionIsExternal/);194 });195});196197describe('Negative Integration Test: Internal Collections, External Ops', async () => {198 let collectionId: number;199 let nftId: number;200201 before(async () => {202 await usingPlaygrounds(async (helper, privateKey) => {203 alice = privateKey('//Alice');204 bob = privateKey('//Bob');205206 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'iceo'});207 collectionId = collection.collectionId;208 nftId = (await collection.mintToken(alice)).tokenId;209 });210 });211212 itSub.ifWithPallets('[Negative] Forbids RMRK operations with the internal collection and NFT (due to the lack of mapping)', [Pallets.RmrkCore], async ({helper}) => {213 const api = helper.getApi();214215 const txChangeOwner = api.tx.rmrkCore.changeCollectionIssuer(collectionId, bob.address);216 await expect(executeTransaction(api, alice, txChangeOwner), 'changing collection issuer')217 .to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);218219 const maxBurns = 10;220 const txBurnItem = api.tx.rmrkCore.burnNft(collectionId, nftId, maxBurns);221 await expect(executeTransaction(api, alice, txBurnItem), 'burning NFT').to.be.rejectedWith(/rmrkCore\.CollectionUnknown/);222 });223});