From c7ac40c1ba37abe8bb91ce8fc590e7d895dfeba5 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Fri, 08 Jul 2022 09:30:42 +0000 Subject: [PATCH] CORE-410 Restor tests --- --- a/tests/src/interfaces/augment-api-query.ts +++ b/tests/src/interfaces/augment-api-query.ts @@ -408,6 +408,7 @@ **/ owned: AugmentedQuery Observable, [u32, PalletEvmAccountBasicCrossAccountIdRepr, u32]> & QueryableStorageEntry; tokenData: AugmentedQuery Observable, [u32, u32]> & QueryableStorageEntry; + tokenProperties: AugmentedQuery Observable, [u32, u32]> & QueryableStorageEntry; tokensBurnt: AugmentedQuery Observable, [u32]> & QueryableStorageEntry; tokensMinted: AugmentedQuery Observable, [u32]> & QueryableStorageEntry; totalSupply: AugmentedQuery Observable, [u32, u32]> & QueryableStorageEntry; --- a/tests/src/interfaces/default/types.ts +++ b/tests/src/interfaces/default/types.ts @@ -2461,12 +2461,14 @@ export interface UpDataStructsCreateReFungibleData extends Struct { readonly constData: Bytes; readonly pieces: u128; + readonly properties: Vec; } /** @name UpDataStructsCreateRefungibleExData */ export interface UpDataStructsCreateRefungibleExData extends Struct { readonly constData: Bytes; readonly users: BTreeMap; + readonly properties: Vec; } /** @name UpDataStructsNestingPermissions */ --- a/tests/src/interfaces/lookup.ts +++ b/tests/src/interfaces/lookup.ts @@ -1502,7 +1502,8 @@ **/ UpDataStructsCreateReFungibleData: { constData: 'Bytes', - pieces: 'u128' + pieces: 'u128', + properties: 'Vec' }, /** * Lookup193: up_data_structs::CreateItemExData> @@ -1527,7 +1528,8 @@ **/ UpDataStructsCreateRefungibleExData: { constData: 'Bytes', - users: 'BTreeMap' + users: 'BTreeMap', + properties: 'Vec' }, /** * Lookup204: pallet_unique_scheduler::pallet::Call --- a/tests/src/interfaces/types-lookup.ts +++ b/tests/src/interfaces/types-lookup.ts @@ -1629,6 +1629,7 @@ export interface UpDataStructsCreateReFungibleData extends Struct { readonly constData: Bytes; readonly pieces: u128; + readonly properties: Vec; } /** @name UpDataStructsCreateItemExData (193) */ @@ -1654,6 +1655,7 @@ export interface UpDataStructsCreateRefungibleExData extends Struct { readonly constData: Bytes; readonly users: BTreeMap; + readonly properties: Vec; } /** @name PalletUniqueSchedulerCall (204) */ --- a/tests/src/nesting/properties.test.ts +++ b/tests/src/nesting/properties.test.ts @@ -806,123 +806,144 @@ await testDeletePropertiesAccordingPermission({type: 'ReFungible'}, 100); }); - // it('Assigns properties to a nested token according to permissions', async () => { - // await usingApi(async api => { - // const propertyKeys: string[] = []; - // let i = 0; - // for (const permission of permissions) { - // for (const signer of permission.signers) { - // const key = i + '_' + signer.address; - // propertyKeys.push(key); + it('Assigns properties to a nested token according to permissions', async () => { + await usingApi(async api => { + const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); + await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}}); + const token = await createItemExpectSuccess(alice, collection, 'NFT'); + const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, token)}); + await addCollectionAdminExpectSuccess(alice, collection, bob.address); + await transferExpectSuccess(collection, token, alice, charlie); - // await expect(executeTransaction( - // api, - // alice, - // api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), - // ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; + const propertyKeys: string[] = []; + let i = 0; + for (const permission of permissions) { + for (const signer of permission.signers) { + const key = i + '_' + signer.address; + propertyKeys.push(key); - // await expect(executeTransaction( - // api, - // signer, - // api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), - // ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; - // } + await expect(executeTransaction( + api, + alice, + api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), + ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; - // i++; - // } + await expect(executeTransaction( + api, + signer, + api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), + ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; + } - // const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toHuman() as any[]; - // const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toHuman().properties as any[]; - // for (let i = 0; i < properties.length; i++) { - // expect(properties[i].value).to.be.equal('Serotonin increase'); - // expect(tokensData[i].value).to.be.equal('Serotonin increase'); - // } - // }); - // }); + i++; + } + + const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toHuman() as any[]; + const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toHuman().properties as any[]; + for (let i = 0; i < properties.length; i++) { + expect(properties[i].value).to.be.equal('Serotonin increase'); + expect(tokensData[i].value).to.be.equal('Serotonin increase'); + } + }); + }); - // it('Changes properties of a nested token according to permissions', async () => { - // await usingApi(async api => { - // const propertyKeys: string[] = []; - // let i = 0; - // for (const permission of permissions) { - // if (!permission.permission.mutable) continue; + it('Changes properties of a nested token according to permissions', async () => { + await usingApi(async api => { + const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); + await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}}); + const token = await createItemExpectSuccess(alice, collection, 'NFT'); + const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, token)}); + await addCollectionAdminExpectSuccess(alice, collection, bob.address); + await transferExpectSuccess(collection, token, alice, charlie); + + const propertyKeys: string[] = []; + let i = 0; + for (const permission of permissions) { + if (!permission.permission.mutable) continue; - // for (const signer of permission.signers) { - // const key = i + '_' + signer.address; - // propertyKeys.push(key); + for (const signer of permission.signers) { + const key = i + '_' + signer.address; + propertyKeys.push(key); - // await expect(executeTransaction( - // api, - // alice, - // api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), - // ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; + await expect(executeTransaction( + api, + alice, + api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), + ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; - // await expect(executeTransaction( - // api, - // signer, - // api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), - // ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; + await expect(executeTransaction( + api, + signer, + api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), + ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; - // await expect(executeTransaction( - // api, - // signer, - // api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin stable'}]), - // ), `on changing property ${i} by ${signer.address}`).to.not.be.rejected; - // } + await expect(executeTransaction( + api, + signer, + api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin stable'}]), + ), `on changing property ${i} by ${signer.address}`).to.not.be.rejected; + } - // i++; - // } + i++; + } - // const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toHuman() as any[]; - // const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toHuman().properties as any[]; - // for (let i = 0; i < properties.length; i++) { - // expect(properties[i].value).to.be.equal('Serotonin stable'); - // expect(tokensData[i].value).to.be.equal('Serotonin stable'); - // } - // }); - // }); + const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toHuman() as any[]; + const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toHuman().properties as any[]; + for (let i = 0; i < properties.length; i++) { + expect(properties[i].value).to.be.equal('Serotonin stable'); + expect(tokensData[i].value).to.be.equal('Serotonin stable'); + } + }); + }); + + it('Deletes properties of a nested token according to permissions', async () => { + await usingApi(async api => { + const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); + await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}}); + const token = await createItemExpectSuccess(alice, collection, 'NFT'); + const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, token)}); + await addCollectionAdminExpectSuccess(alice, collection, bob.address); + await transferExpectSuccess(collection, token, alice, charlie); - // it('Deletes properties of a nested token according to permissions', async () => { - // await usingApi(async api => { - // const propertyKeys: string[] = []; - // let i = 0; + const propertyKeys: string[] = []; + let i = 0; - // for (const permission of permissions) { - // if (!permission.permission.mutable) continue; + for (const permission of permissions) { + if (!permission.permission.mutable) continue; - // for (const signer of permission.signers) { - // const key = i + '_' + signer.address; - // propertyKeys.push(key); + for (const signer of permission.signers) { + const key = i + '_' + signer.address; + propertyKeys.push(key); - // await expect(executeTransaction( - // api, - // alice, - // api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), - // ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; + await expect(executeTransaction( + api, + alice, + api.tx.unique.setTokenPropertyPermissions(collection, [{key: key, permission: permission.permission}]), + ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected; - // await expect(executeTransaction( - // api, - // signer, - // api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), - // ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; + await expect(executeTransaction( + api, + signer, + api.tx.unique.setTokenProperties(collection, nestedToken, [{key: key, value: 'Serotonin increase'}]), + ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected; - // await expect(executeTransaction( - // api, - // signer, - // api.tx.unique.deleteTokenProperties(collection, nestedToken, [key]), - // ), `on deleting property ${i} by ${signer.address}`).to.not.be.rejected; - // } + await expect(executeTransaction( + api, + signer, + api.tx.unique.deleteTokenProperties(collection, nestedToken, [key]), + ), `on deleting property ${i} by ${signer.address}`).to.not.be.rejected; + } - // i++; - // } + i++; + } - // const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toJSON() as any[]; - // expect(properties).to.be.empty; - // const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toJSON().properties as any[]; - // expect(tokensData).to.be.empty; - // expect((await api.query.nonfungible.tokenProperties(collection, nestedToken)).toJSON().consumedSpace).to.be.equal(0); - // }); - // }); + const properties = (await api.rpc.unique.tokenProperties(collection, nestedToken, propertyKeys)).toJSON() as any[]; + expect(properties).to.be.empty; + const tokensData = (await api.rpc.unique.tokenData(collection, nestedToken, propertyKeys)).toJSON().properties as any[]; + expect(tokensData).to.be.empty; + expect((await api.query.nonfungible.tokenProperties(collection, nestedToken)).toJSON().consumedSpace).to.be.equal(0); + }); + }); }); describe('Negative Integration Test: Token Properties', () => { --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -1414,7 +1414,7 @@ tx = api.tx.unique.createItem(collectionId, to, createData as any); } - const events = await submitTransactionAsync(sender, tx); + const events = await executeTransaction(api, sender, tx); const result = getCreateItemResult(events); const itemCountAfter = await getLastTokenId(api, collectionId); -- gitstuff