From 764dfd599fffa82980e7fb2e360d94c4aad5c67e Mon Sep 17 00:00:00 2001 From: Andrey Kuznetsov Date: Sun, 29 May 2022 18:21:31 +0000 Subject: [PATCH] Quick fix for nesting tests --- --- a/tests/src/nesting/graphs.test.ts +++ b/tests/src/nesting/graphs.test.ts @@ -14,7 +14,7 @@ * ``` */ async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise { - const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}})); + const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', permissions: {nesting: 'Owner'}})); const {collectionId} = getCreateCollectionResult(events); await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})})); --- a/tests/src/nesting/nest.test.ts +++ b/tests/src/nesting/nest.test.ts @@ -8,11 +8,11 @@ createItemExpectSuccess, enableAllowListExpectSuccess, enablePublicMintingExpectSuccess, - getTokenOwner, + getTokenOwner, getTopmostTokenOwner, - setCollectionLimitsExpectSuccess, - transferExpectFailure, - transferExpectSuccess, + setCollectionPermissionsExceptSuccess, + transferExpectFailure, + transferExpectSuccess, transferFromExpectSuccess, } from '../util/helpers'; import {IKeyringPair} from '@polkadot/types/types'; @@ -31,7 +31,7 @@ it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Create a nested token @@ -63,7 +63,7 @@ it('NFT: allows an Owner to nest/unnest their token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Create a nested token @@ -82,7 +82,7 @@ it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Create a nested token @@ -103,7 +103,7 @@ it('Fungible: allows an Owner to nest/unnest their token', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address}); const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; @@ -130,7 +130,7 @@ const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}}); // Create a nested token await expect(executeTransaction(api, alice, api.tx.unique.createItem( @@ -150,7 +150,7 @@ it('ReFungible: allows an Owner to nest/unnest their token', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address}); const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; @@ -177,7 +177,7 @@ const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}}); // Create a nested token await expect(executeTransaction(api, alice, api.tx.unique.createItem( @@ -204,7 +204,7 @@ it('Disallows excessive token nesting', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Create a nested-token matryoshka @@ -226,7 +226,7 @@ it('NFT: disallows to nest token if nesting is disabled', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Disabled'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Try to create a nested token @@ -248,7 +248,7 @@ it('NFT: disallows a non-Owner to nest someone else\'s token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); await addToAllowListExpectSuccess(alice, collection, bob.address); await enableAllowListExpectSuccess(alice, collection); @@ -274,7 +274,7 @@ it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}}); await addToAllowListExpectSuccess(alice, collection, bob.address); await enableAllowListExpectSuccess(alice, collection); @@ -300,7 +300,7 @@ it('NFT: disallows to nest token in an unlisted collection', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: {OwnerRestricted:[]}}); // Create a token to attempt to be nested into const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); @@ -324,7 +324,7 @@ it('Fungible: disallows to nest token if nesting is disabled', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'}); const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; @@ -352,7 +352,7 @@ it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'}); await addToAllowListExpectSuccess(alice, collectionNFT, bob.address); await enableAllowListExpectSuccess(alice, collectionNFT); @@ -389,7 +389,7 @@ const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}}); // Try to create a nested token in the wrong collection await expect(executeTransaction(api, alice, api.tx.unique.createItem( @@ -407,7 +407,7 @@ it('Fungible: disallows to nest token in an unlisted collection', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}}); // Create a token to attempt to be nested into const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT'); @@ -433,7 +433,7 @@ it('ReFungible: disallows to nest token if nesting is disabled', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Disabled'}); const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; @@ -463,7 +463,7 @@ it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: 'Owner'}); await addToAllowListExpectSuccess(alice, collectionNFT, bob.address); await enableAllowListExpectSuccess(alice, collectionNFT); @@ -500,7 +500,7 @@ const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)}; const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}}); // Try to create a nested token in the wrong collection await expect(executeTransaction(api, alice, api.tx.unique.createItem( @@ -518,7 +518,7 @@ it('ReFungible: disallows to nest token to an unlisted collection', async () => { await usingApi(async api => { const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}}); + await setCollectionPermissionsExceptSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}}); // Create a token to attempt to be nested into const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT'); --- a/tests/src/nesting/rules-smoke.test.ts +++ b/tests/src/nesting/rules-smoke.test.ts @@ -14,8 +14,8 @@ const bob = privateKey('//Bob'); const events = await executeTransaction(api, alice, api.tx.unique.createCollectionEx({ mode: 'NFT', - limits: { - nestingRule: {OwnerRestricted: []}, + permissions: { + nesting: {OwnerRestricted: []}, }, })); const collection = getCreateCollectionResult(events).collectionId; @@ -39,7 +39,7 @@ it('called for nonfungible', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {ConstData: []}}))) + await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {properties: []}}))) .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/); const token = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address}); @@ -51,7 +51,7 @@ it('called for refungible', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {ConstData: []}}))) + await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {}}))) .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/); const token = await createItemExpectSuccess(alice, collection, 'ReFungible', {Substrate: alice.address}); --- a/tests/src/nesting/unnest.test.ts +++ b/tests/src/nesting/unnest.test.ts @@ -8,7 +8,7 @@ getBalance, getTokenOwner, normalizeAccountId, - setCollectionLimitsExpectSuccess, + setCollectionPermissionsExceptSuccess, transferExpectSuccess, transferFromExpectSuccess, } from '../util/helpers'; @@ -28,7 +28,7 @@ it('NFT: allows the owner to successfully unnest a token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)}; @@ -57,7 +57,7 @@ it('Fungible: allows the owner to successfully unnest a token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)}; @@ -84,7 +84,7 @@ it('ReFungible: allows the owner to successfully unnest a token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)}; @@ -119,7 +119,7 @@ it('Disallows a non-owner to unnest/burn a token', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken)}; @@ -149,7 +149,7 @@ // Recursive nesting it('Prevents Ouroboros creation', async () => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'}); + await setCollectionPermissionsExceptSuccess(alice, collection, {nesting: 'Owner'}); const targetToken = await createItemExpectSuccess(alice, collection, 'NFT'); // Create a nested token ouroboros --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -325,7 +325,7 @@ }; export async function createCollectionExpectSuccess(params: Partial = {}): Promise { - const {name, description, mode, tokenPrefix, schemaVersion} = {...defaultCreateCollectionParams, ...params}; + const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params}; let collectionId = 0; await usingApi(async (api) => { @@ -348,8 +348,7 @@ name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), - mode: modeprm as any, - schemaVersion: schemaVersion, + mode: modeprm as any }); const events = await submitTransactionAsync(alicePrivateKey, tx); const result = getCreateCollectionResult(events); @@ -555,6 +554,16 @@ }); } +export const setCollectionPermissionsExceptSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => { + await usingApi(async(api) => { + const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) { await usingApi(async (api) => { const tx = api.tx.unique.setCollectionLimits(collectionId, limits); @@ -1299,7 +1308,7 @@ // What to expect // tslint:disable-next-line:no-unused-expression expect(result.success).to.be.true; - expect(collection.access.toHuman()).to.be.equal(accessMode); + expect(collection.permissions.access.toHuman()).to.be.equal(accessMode); }); } @@ -1344,7 +1353,7 @@ // Get the collection const collection = await queryCollectionExpectSuccess(api, collectionId); - expect(collection.mintMode.toHuman()).to.be.equal(enabled); + expect(collection.permissions.mintMode.toHuman()).to.be.equal(enabled); }); } -- gitstuff