git.delta.rocks / unique-network / refs/commits / ea778c464851

difftreelog

fix PR

Trubnikov Sergey2022-12-15parent: #214ea65.patch.diff
in: master

3 files changed

modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -19,7 +19,7 @@
 import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';
 import {IEvent, TCollectionMode} from '../util/playgrounds/types';
 import {Pallets, requirePalletsOrSkip} from '../util';
-import {NormalizedEvent} from './util/playgrounds/types';
+import {EthTokenPermissions, NormalizedEvent} from './util/playgrounds/types';
 
 let donor: IKeyringPair;
   
@@ -119,7 +119,13 @@
     ethEvents.push(event);
   });
   const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);
-  await collection.methods.setTokenPropertyPermissions([['testKey', [[0, true], [1, true], [2, true]]]]).send({from: owner});
+  await collection.methods.setTokenPropertyPermissions([
+    ['A', [
+      [EthTokenPermissions.Mutable, true], 
+      [EthTokenPermissions.TokenOwner, true], 
+      [EthTokenPermissions.CollectionAdmin, true]],
+    ],
+  ]).send({from: owner});
   await helper.wait.newBlocks(1);
   expect(ethEvents).to.be.like([
     {
@@ -374,7 +380,13 @@
   const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
   const result = await collection.methods.mint(owner).send({from: owner});
   const tokenId = result.events.Transfer.returnValues.tokenId;
-  await collection.methods.setTokenPropertyPermissions([['A', [[0, true], [1, true], [2, true]]]]).send({from: owner});
+  await collection.methods.setTokenPropertyPermissions([
+    ['A', [
+      [EthTokenPermissions.Mutable, true], 
+      [EthTokenPermissions.TokenOwner, true], 
+      [EthTokenPermissions.CollectionAdmin, true]],
+    ],
+  ]).send({from: owner});
 
 
   const ethEvents: any = [];
modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
before · tests/src/eth/tokenProperties.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {Contract} from 'web3-eth-contract';19import {itEth, usingEthPlaygrounds, expect} from './util';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import {Pallets} from '../util';22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';2324describe('EVM token properties', () => {25  let donor: IKeyringPair;26  let alice: IKeyringPair;2728  before(async function() {29    await usingEthPlaygrounds(async (helper, privateKey) => {30      donor = await privateKey({filename: __filename});31      [alice] = await helper.arrange.createAccounts([100n], donor);32    });33  });3435  [36    {mode: 'nft' as const, requiredPallets: []},37    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},38  ].map(testCase =>39    itEth.ifWithPallets.only(`[${testCase.mode}] Set and get token property permissions`, testCase.requiredPallets, async({helper}) => {40      const owner = await helper.eth.createAccountWithBalance(donor);41      const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);42      for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {43        const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');44        const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);45        await collection.methods.addCollectionAdminCross(caller).send({from: owner});4647        await collection.methods.setTokenPropertyPermissions([['testKey', [[0, mutable], [1, tokenOwner], [2, collectionAdmin]]]]).send({from: caller.eth});48      49        expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{50          key: 'testKey',51          permission: {mutable, collectionAdmin, tokenOwner},52        }]);5354        expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([55          ['testKey', [['0', mutable], ['1', tokenOwner], ['2', collectionAdmin]]],56        ]);57      }58    }));5960  [61    {62      method: 'setProperties',63      methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]],64      expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}],65    },66    {67      method: 'setProperty' /*Soft-deprecated*/, 68      methodParams: ['testKey1', Buffer.from('testValue1')],69      expectedProps: [{key: 'testKey1', value: 'testValue1'}],70    },71  ].map(testCase => 72    itEth(`[${testCase.method}] Can be set`, async({helper}) => {73      const caller = await helper.eth.createAccountWithBalance(donor);74      const collection = await helper.nft.mintCollection(alice, {75        tokenPropertyPermissions: [{76          key: 'testKey1',77          permission: {78            collectionAdmin: true,79          },80        }, {81          key: 'testKey2',82          permission: {83            collectionAdmin: true,84          },85        }],86      });8788      await collection.addAdmin(alice, {Ethereum: caller});89      const token = await collection.mintToken(alice);90  91      const collectionEvm = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller, testCase.method === 'setProperty');92  93      await collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller});94  95      const properties = await token.getProperties();96      expect(properties).to.deep.equal(testCase.expectedProps);97    }));98  99  [100    {mode: 'nft' as const, requiredPallets: []},101    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},102  ].map(testCase => 103    itEth.ifWithPallets(`Can be multiple set/read for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {104      const caller = await helper.eth.createAccountWithBalance(donor);105      106      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });107      const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,108        collectionAdmin: true,109        mutable: true}}; });110      111      const collection = await helper[testCase.mode].mintCollection(alice, {112        tokenPrefix: 'ethp',113        tokenPropertyPermissions: permissions,114      }) as UniqueNFTCollection | UniqueRFTCollection;115      116      const token = await collection.mintToken(alice);117      118      const valuesBefore = await token.getProperties(properties.map(p => p.key));119      expect(valuesBefore).to.be.deep.equal([]);120      121      122      await collection.addAdmin(alice, {Ethereum: caller});123      124      const address = helper.ethAddress.fromCollectionId(collection.collectionId);125      const contract = helper.ethNativeContract.collection(address, testCase.mode, caller);126      127      expect(await contract.methods.properties(token.tokenId, []).call()).to.be.deep.equal([]);128  129      await contract.methods.setProperties(token.tokenId, properties).send({from: caller});130  131      const values = await token.getProperties(properties.map(p => p.key));132      expect(values).to.be.deep.equal(properties.map(p => { return {key: p.key, value: p.value.toString()}; }));133      134      expect(await contract.methods.properties(token.tokenId, []).call()).to.be.like(properties135        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));136      137      expect(await contract.methods.properties(token.tokenId, [properties[0].key]).call())138        .to.be.like([helper.ethProperty.property(properties[0].key, properties[0].value.toString())]);139    }));140  141  [142    {mode: 'nft' as const, requiredPallets: []},143    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},144  ].map(testCase => 145    itEth.ifWithPallets(`Can be deleted for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {146      const caller = await helper.eth.createAccountWithBalance(donor);147      const collection = await helper[testCase.mode].mintCollection(alice, {148        tokenPropertyPermissions: [{149          key: 'testKey',150          permission: {151            mutable: true,152            collectionAdmin: true,153          },154        },155        {156          key: 'testKey_1',157          permission: {158            mutable: true,159            collectionAdmin: true,160          },161        }],162      });163    164      const token = await collection.mintToken(alice);165      await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}, {key: 'testKey_1', value: 'testValue_1'}]);166      expect(await token.getProperties()).to.has.length(2);167168      await collection.addAdmin(alice, {Ethereum: caller});169170      const address = helper.ethAddress.fromCollectionId(collection.collectionId);171      const contract = helper.ethNativeContract.collection(address, testCase.mode, caller);172173      await contract.methods.deleteProperties(token.tokenId, ['testKey', 'testKey_1']).send({from: caller});174175      const result = await token.getProperties(['testKey', 'testKey_1']);176      expect(result.length).to.equal(0);177    }));178179  itEth('Can be read', async({helper}) => {180    const caller = helper.eth.createAccount();181    const collection = await helper.nft.mintCollection(alice, {182      tokenPropertyPermissions: [{183        key: 'testKey',184        permission: {185          collectionAdmin: true,186        },187      }],188    });189  190    const token = await collection.mintToken(alice);191    await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);192193    const address = helper.ethAddress.fromCollectionId(collection.collectionId);194    const contract = helper.ethNativeContract.collection(address, 'nft', caller);195196    const value = await contract.methods.property(token.tokenId, 'testKey').call();197    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));198  });199});200201describe('EVM token properties negative', () => {202  let donor: IKeyringPair;203  let alice: IKeyringPair;204  let caller: string;205  let aliceCollection: UniqueNFTCollection;206  let token: UniqueNFToken;207  const tokenProps = [{key: 'testKey_1', value: 'testValue_1'}, {key: 'testKey_2', value: 'testValue_2'}];208  let collectionEvm: Contract;209210  before(async function() {211    await usingEthPlaygrounds(async (helper, privateKey) => {212      donor = await privateKey({filename: __filename});213      [alice] = await helper.arrange.createAccounts([100n], donor);214    });215  });216217  beforeEach(async () => {218    // 1. create collection with props: testKey_1, testKey_2219    // 2. create token and set props testKey_1, testKey_2220    await usingEthPlaygrounds(async (helper) => {221      aliceCollection = await helper.nft.mintCollection(alice, {222        tokenPropertyPermissions: [{223          key: 'testKey_1',224          permission: {225            mutable: true,226            collectionAdmin: true,227          },228        },229        {230          key: 'testKey_2',231          permission: {232            mutable: true,233            collectionAdmin: true,234          },235        }],236      }); 237      token = await aliceCollection.mintToken(alice);238      await token.setProperties(alice, tokenProps);239      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);240    });241  });242243  [244    {method: 'setProperty', methodParams: [tokenProps[1].key, Buffer.from('newValue')]},245    {method: 'setProperties', methodParams: [[{key: tokenProps[1].key, value: Buffer.from('newValue')}]]},246  ].map(testCase =>247    itEth(`[${testCase.method}] Cannot set properties of non-owned collection`, async ({helper}) => {248      caller = await helper.eth.createAccountWithBalance(donor);249      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);250      // Caller not an owner and not an admin, so he cannot set properties:251      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');252      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;253254      // Props have not changed:255      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));256      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();257      expect(actualProps).to.deep.eq(expectedProps);258    }));259260  [261    {method: 'setProperty', methodParams: ['testKey_3', Buffer.from('testValue3')]},262    {method: 'setProperties', methodParams: [[{key: 'testKey_3', value: Buffer.from('testValue3')}]]},263  ].map(testCase =>264    itEth(`[${testCase.method}] Cannot set non-existing properties`, async ({helper}) => {265      caller = await helper.eth.createAccountWithBalance(donor);266      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);267      await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});268269      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');270      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;271272      // Props have not changed:273      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));274      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();275      expect(actualProps).to.deep.eq(expectedProps);276    }));277278  [279    {method: 'deleteProperty', methodParams: ['testKey_2']},280    {method: 'deleteProperties', methodParams: [['testKey_2']]},281  ].map(testCase =>  282    itEth(`[${testCase.method}] Cannot delete properties of non-owned collection`, async ({helper}) => {283      caller = await helper.eth.createAccountWithBalance(donor);284      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');285      // Caller not an owner and not an admin, so he cannot set properties:286      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');287      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;288289      // Props have not changed:290      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));291      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();292      expect(actualProps).to.deep.eq(expectedProps);293    }));294   295  [296    {method: 'deleteProperty', methodParams: ['testKey_3']},297    {method: 'deleteProperties', methodParams: [['testKey_3']]},298  ].map(testCase =>  299    itEth(`[${testCase.method}] Cannot delete non-existing properties`, async ({helper}) => {300      caller = await helper.eth.createAccountWithBalance(donor);301      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');302      await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});303      // Caller cannot delete non-existing properties:304      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');305      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;306      // Props have not changed:307      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));308      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();309      expect(actualProps).to.deep.eq(expectedProps);310    }));311});312313314type ElementOf<A> = A extends readonly (infer T)[] ? T : never;315function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {316  if(args.length === 0) {317    yield internalRest as any;318    return;319  }320  for(const value of args[0]) {321    yield* cartesian([...internalRest, value], ...args.slice(1)) as any;322  }323}
after · tests/src/eth/tokenProperties.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {Contract} from 'web3-eth-contract';19import {itEth, usingEthPlaygrounds, expect} from './util';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import {Pallets} from '../util';22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';23import {EthTokenPermissions} from './util/playgrounds/types';2425describe('EVM token properties', () => {26  let donor: IKeyringPair;27  let alice: IKeyringPair;2829  before(async function() {30    await usingEthPlaygrounds(async (helper, privateKey) => {31      donor = await privateKey({filename: __filename});32      [alice] = await helper.arrange.createAccounts([100n], donor);33    });34  });3536  [37    {mode: 'nft' as const, requiredPallets: []},38    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},39  ].map(testCase =>40    itEth.ifWithPallets(`[${testCase.mode}] Set and get token property permissions`, testCase.requiredPallets, async({helper}) => {41      const owner = await helper.eth.createAccountWithBalance(donor);42      const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);43      for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {44        const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');45        const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);46        await collection.methods.addCollectionAdminCross(caller).send({from: owner});4748        await collection.methods.setTokenPropertyPermissions([49          ['testKey', [50            [EthTokenPermissions.Mutable, mutable], 51            [EthTokenPermissions.TokenOwner, tokenOwner], 52            [EthTokenPermissions.CollectionAdmin, collectionAdmin]],53          ],54        ]).send({from: caller.eth});55      56        expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{57          key: 'testKey',58          permission: {mutable, collectionAdmin, tokenOwner},59        }]);6061        expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([62          ['testKey', [63            [EthTokenPermissions.Mutable.toString(), mutable], 64            [EthTokenPermissions.TokenOwner.toString(), tokenOwner], 65            [EthTokenPermissions.CollectionAdmin.toString(), collectionAdmin]],66          ],67        ]);68      }69    }));7071  [72    {73      method: 'setProperties',74      methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]],75      expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}],76    },77    {78      method: 'setProperty' /*Soft-deprecated*/, 79      methodParams: ['testKey1', Buffer.from('testValue1')],80      expectedProps: [{key: 'testKey1', value: 'testValue1'}],81    },82  ].map(testCase => 83    itEth(`[${testCase.method}] Can be set`, async({helper}) => {84      const caller = await helper.eth.createAccountWithBalance(donor);85      const collection = await helper.nft.mintCollection(alice, {86        tokenPropertyPermissions: [{87          key: 'testKey1',88          permission: {89            collectionAdmin: true,90          },91        }, {92          key: 'testKey2',93          permission: {94            collectionAdmin: true,95          },96        }],97      });9899      await collection.addAdmin(alice, {Ethereum: caller});100      const token = await collection.mintToken(alice);101  102      const collectionEvm = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller, testCase.method === 'setProperty');103  104      await collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller});105  106      const properties = await token.getProperties();107      expect(properties).to.deep.equal(testCase.expectedProps);108    }));109  110  [111    {mode: 'nft' as const, requiredPallets: []},112    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},113  ].map(testCase => 114    itEth.ifWithPallets(`Can be multiple set/read for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {115      const caller = await helper.eth.createAccountWithBalance(donor);116      117      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });118      const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,119        collectionAdmin: true,120        mutable: true}}; });121      122      const collection = await helper[testCase.mode].mintCollection(alice, {123        tokenPrefix: 'ethp',124        tokenPropertyPermissions: permissions,125      }) as UniqueNFTCollection | UniqueRFTCollection;126      127      const token = await collection.mintToken(alice);128      129      const valuesBefore = await token.getProperties(properties.map(p => p.key));130      expect(valuesBefore).to.be.deep.equal([]);131      132      133      await collection.addAdmin(alice, {Ethereum: caller});134      135      const address = helper.ethAddress.fromCollectionId(collection.collectionId);136      const contract = helper.ethNativeContract.collection(address, testCase.mode, caller);137      138      expect(await contract.methods.properties(token.tokenId, []).call()).to.be.deep.equal([]);139  140      await contract.methods.setProperties(token.tokenId, properties).send({from: caller});141  142      const values = await token.getProperties(properties.map(p => p.key));143      expect(values).to.be.deep.equal(properties.map(p => { return {key: p.key, value: p.value.toString()}; }));144      145      expect(await contract.methods.properties(token.tokenId, []).call()).to.be.like(properties146        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));147      148      expect(await contract.methods.properties(token.tokenId, [properties[0].key]).call())149        .to.be.like([helper.ethProperty.property(properties[0].key, properties[0].value.toString())]);150    }));151  152  [153    {mode: 'nft' as const, requiredPallets: []},154    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},155  ].map(testCase => 156    itEth.ifWithPallets(`Can be deleted for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {157      const caller = await helper.eth.createAccountWithBalance(donor);158      const collection = await helper[testCase.mode].mintCollection(alice, {159        tokenPropertyPermissions: [{160          key: 'testKey',161          permission: {162            mutable: true,163            collectionAdmin: true,164          },165        },166        {167          key: 'testKey_1',168          permission: {169            mutable: true,170            collectionAdmin: true,171          },172        }],173      });174    175      const token = await collection.mintToken(alice);176      await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}, {key: 'testKey_1', value: 'testValue_1'}]);177      expect(await token.getProperties()).to.has.length(2);178179      await collection.addAdmin(alice, {Ethereum: caller});180181      const address = helper.ethAddress.fromCollectionId(collection.collectionId);182      const contract = helper.ethNativeContract.collection(address, testCase.mode, caller);183184      await contract.methods.deleteProperties(token.tokenId, ['testKey', 'testKey_1']).send({from: caller});185186      const result = await token.getProperties(['testKey', 'testKey_1']);187      expect(result.length).to.equal(0);188    }));189190  itEth('Can be read', async({helper}) => {191    const caller = helper.eth.createAccount();192    const collection = await helper.nft.mintCollection(alice, {193      tokenPropertyPermissions: [{194        key: 'testKey',195        permission: {196          collectionAdmin: true,197        },198      }],199    });200  201    const token = await collection.mintToken(alice);202    await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);203204    const address = helper.ethAddress.fromCollectionId(collection.collectionId);205    const contract = helper.ethNativeContract.collection(address, 'nft', caller);206207    const value = await contract.methods.property(token.tokenId, 'testKey').call();208    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));209  });210});211212describe('EVM token properties negative', () => {213  let donor: IKeyringPair;214  let alice: IKeyringPair;215  let caller: string;216  let aliceCollection: UniqueNFTCollection;217  let token: UniqueNFToken;218  const tokenProps = [{key: 'testKey_1', value: 'testValue_1'}, {key: 'testKey_2', value: 'testValue_2'}];219  let collectionEvm: Contract;220221  before(async function() {222    await usingEthPlaygrounds(async (helper, privateKey) => {223      donor = await privateKey({filename: __filename});224      [alice] = await helper.arrange.createAccounts([100n], donor);225    });226  });227228  beforeEach(async () => {229    // 1. create collection with props: testKey_1, testKey_2230    // 2. create token and set props testKey_1, testKey_2231    await usingEthPlaygrounds(async (helper) => {232      aliceCollection = await helper.nft.mintCollection(alice, {233        tokenPropertyPermissions: [{234          key: 'testKey_1',235          permission: {236            mutable: true,237            collectionAdmin: true,238          },239        },240        {241          key: 'testKey_2',242          permission: {243            mutable: true,244            collectionAdmin: true,245          },246        }],247      }); 248      token = await aliceCollection.mintToken(alice);249      await token.setProperties(alice, tokenProps);250      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);251    });252  });253254  [255    {method: 'setProperty', methodParams: [tokenProps[1].key, Buffer.from('newValue')]},256    {method: 'setProperties', methodParams: [[{key: tokenProps[1].key, value: Buffer.from('newValue')}]]},257  ].map(testCase =>258    itEth(`[${testCase.method}] Cannot set properties of non-owned collection`, async ({helper}) => {259      caller = await helper.eth.createAccountWithBalance(donor);260      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);261      // Caller not an owner and not an admin, so he cannot set properties:262      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');263      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;264265      // Props have not changed:266      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));267      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();268      expect(actualProps).to.deep.eq(expectedProps);269    }));270271  [272    {method: 'setProperty', methodParams: ['testKey_3', Buffer.from('testValue3')]},273    {method: 'setProperties', methodParams: [[{key: 'testKey_3', value: Buffer.from('testValue3')}]]},274  ].map(testCase =>275    itEth(`[${testCase.method}] Cannot set non-existing properties`, async ({helper}) => {276      caller = await helper.eth.createAccountWithBalance(donor);277      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);278      await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});279280      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');281      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;282283      // Props have not changed:284      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));285      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();286      expect(actualProps).to.deep.eq(expectedProps);287    }));288289  [290    {method: 'deleteProperty', methodParams: ['testKey_2']},291    {method: 'deleteProperties', methodParams: [['testKey_2']]},292  ].map(testCase =>  293    itEth(`[${testCase.method}] Cannot delete properties of non-owned collection`, async ({helper}) => {294      caller = await helper.eth.createAccountWithBalance(donor);295      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');296      // Caller not an owner and not an admin, so he cannot set properties:297      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');298      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;299300      // Props have not changed:301      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));302      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();303      expect(actualProps).to.deep.eq(expectedProps);304    }));305   306  [307    {method: 'deleteProperty', methodParams: ['testKey_3']},308    {method: 'deleteProperties', methodParams: [['testKey_3']]},309  ].map(testCase =>  310    itEth(`[${testCase.method}] Cannot delete non-existing properties`, async ({helper}) => {311      caller = await helper.eth.createAccountWithBalance(donor);312      collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');313      await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});314      // Caller cannot delete non-existing properties:315      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');316      await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;317      // Props have not changed:318      const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));319      const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();320      expect(actualProps).to.deep.eq(expectedProps);321    }));322});323324325type ElementOf<A> = A extends readonly (infer T)[] ? T : never;326function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {327  if(args.length === 0) {328    yield internalRest as any;329    return;330  }331  for(const value of args[0]) {332    yield* cartesian([...internalRest, value], ...args.slice(1)) as any;333  }334}
modifiedtests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/types.ts
+++ b/tests/src/eth/util/playgrounds/types.ts
@@ -20,3 +20,8 @@
 
 export type EthProperty = string[];
 
+export enum EthTokenPermissions {
+  Mutable,
+  TokenOwner,
+  CollectionAdmin
+}
\ No newline at end of file