From f5a3434a83480771f6def24ead015cc92cf59a3c Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 21 Sep 2022 13:19:47 +0000 Subject: [PATCH] fix: createMultipleItemsEx remove skip tests --- --- a/tests/src/createMultipleItemsEx.test.ts +++ b/tests/src/createMultipleItemsEx.test.ts @@ -16,8 +16,6 @@ import {IKeyringPair} from '@polkadot/types/types'; import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds'; -import usingApi, {executeTransaction} from './substrate/substrate-api'; -import {createCollectionExpectSuccess, getBalance, getLastTokenId, getTokenProperties, requirePallets} from './util/helpers'; import {IProperty} from './util/playgrounds/types'; describe('Integration Test: createMultipleItemsEx', () => { @@ -173,95 +171,93 @@ } }); - it.skip('can initialize fungible with multiple owners', async () => { - const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); + itSub('can initialize fungible with multiple owners', async ({helper}) => { + const collection = await helper.ft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + }, 0); + + const api = helper.api; + await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, { + Fungible: new Map([ + [JSON.stringify({Substrate: alice.address}), 50], + [JSON.stringify({Substrate: bob.address}), 100], + ]), + })); - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - Fungible: new Map([ - [JSON.stringify({Substrate: alice.address}), 50], - [JSON.stringify({Substrate: bob.address}), 100], - ]), - })); + expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(50n); + expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(100n); + }); - expect(await getBalance(api, collection, alice.address, 0)).to.equal(50n); - expect(await getBalance(api, collection, bob.address, 0)).to.equal(100n); + itSub.ifWithPallets('can initialize an RFT with multiple owners', [Pallets.ReFungible], async ({helper}) => { + const collection = await helper.rft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ + {key: 'k', permission: {tokenOwner: true, mutable: false, collectionAdmin: false}}, + ], }); + + const api = helper.api; + await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, { + RefungibleMultipleOwners: { + users: new Map([ + [JSON.stringify({Substrate: alice.address}), 1], + [JSON.stringify({Substrate: bob.address}), 2], + ]), + properties: [ + {key: 'k', value: 'v'}, + ], + }, + })); + const tokenId = await collection.getLastTokenId(); + expect(tokenId).to.be.equal(1); + expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n); + expect(await collection.getTokenBalance(1, {Substrate: bob.address})).to.be.equal(2n); }); - it.skip('can initialize an RFT with multiple owners', async function() { - await requirePallets(this, [Pallets.ReFungible]); + itSub.ifWithPallets('can initialize multiple RFTs with the same owner', [Pallets.ReFungible], async ({helper}) => { + const collection = await helper.rft.mintCollection(alice, { + name: 'name', + description: 'descr', + tokenPrefix: 'COL', + tokenPropertyPermissions: [ + {key: 'k', permission: {tokenOwner: true, mutable: false, collectionAdmin: false}}, + ], + }); - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await executeTransaction( - api, - alice, - api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]), - ); + const api = helper.api; - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - RefungibleMultipleOwners: { - users: new Map([ - [JSON.stringify({Substrate: alice.address}), 1], - [JSON.stringify({Substrate: bob.address}), 2], - ]), + await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, { + RefungibleMultipleItems: [ + { + user: {Substrate: alice.address}, pieces: 1, properties: [ - {key: 'data', value: 'testValue'}, + {key: 'k', value: 'v1'}, + ], + }, + { + user: {Substrate: alice.address}, pieces: 3, + properties: [ + {key: 'k', value: 'v2'}, ], }, - })); + ], + })); - const itemsListIndexAfter = await getLastTokenId(api, collection); - expect(itemsListIndexAfter).to.be.equal(1); + expect(await collection.getLastTokenId()).to.be.equal(2); + expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n); + expect(await collection.getTokenBalance(2, {Substrate: alice.address})).to.be.equal(3n); - expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n); - expect(await getBalance(api, collection, bob.address, 1)).to.be.equal(2n); - expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue'); - }); - }); + const tokenData1 = await helper.rft.getToken(collection.collectionId, 1); + expect(tokenData1).to.not.be.null; + expect(tokenData1?.properties[0]).to.be.deep.equal({key: 'k', value: 'v1'}); - it.skip('can initialize multiple RFTs with the same owner', async function() { - await requirePallets(this, [Pallets.ReFungible]); - - await usingApi(async (api, privateKeyWrapper) => { - const alice = privateKeyWrapper('//Alice'); - const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); - await executeTransaction( - api, - alice, - api.tx.unique.setTokenPropertyPermissions(collection, [{key: 'data', permission: {tokenOwner: true}}]), - ); - - await executeTransaction(api, alice, api.tx.unique.createMultipleItemsEx(collection, { - RefungibleMultipleItems: [ - { - user: {Substrate: alice.address}, pieces: 1, - properties: [ - {key: 'data', value: 'testValue1'}, - ], - }, - { - user: {Substrate: alice.address}, pieces: 3, - properties: [ - {key: 'data', value: 'testValue2'}, - ], - }, - ], - })); - - const itemsListIndexAfter = await getLastTokenId(api, collection); - expect(itemsListIndexAfter).to.be.equal(2); - - expect(await getBalance(api, collection, alice.address, 1)).to.be.equal(1n); - expect(await getBalance(api, collection, alice.address, 2)).to.be.equal(3n); - expect((await getTokenProperties(api, collection, 1, ['data']))[0].value).to.be.equal('testValue1'); - expect((await getTokenProperties(api, collection, 2, ['data']))[0].value).to.be.equal('testValue2'); - }); + const tokenData2 = await helper.rft.getToken(collection.collectionId, 2); + expect(tokenData2).to.not.be.null; + expect(tokenData2?.properties[0]).to.be.deep.equal({key: 'k', value: 'v2'}); }); }); -- gitstuff