1import {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds} from './../util/playgrounds/index';3import {itEth, expect} from '../eth/util/playgrounds';45describe('EVM token properties', () => {6 let donor: IKeyringPair;7 let alice: IKeyringPair;89 before(async () => {10 await usingPlaygrounds(async (helper, privateKey) => {11 donor = privateKey('//Alice');12 [alice] = await helper.arrange.createAccounts([1000n], donor);13 });14 });1516 itEth('Can be reconfigured', async({helper}) => {17 const caller = await helper.eth.createAccountWithBalance(donor);1819 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {20 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});21 await collection.addAdmin(alice, {Ethereum: caller});2223 const address = helper.ethAddress.fromCollectionId(collection.collectionId);24 const contract = helper.ethNativeContract.collection(address, 'nft', caller);2526 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});27 28 const state = await collection.getPropertyPermissions();29 expect(state).to.be.deep.equal([{30 key: 'testKey',31 permission: {mutable, collectionAdmin, tokenOwner},32 }]);33 }34 });3536 itEth('Can be set', async({helper}) => {37 const caller = await helper.eth.createAccountWithBalance(donor);38 const collection = await helper.nft.mintCollection(alice, {39 tokenPrefix: 'ethp',40 tokenPropertyPermissions: [{41 key: 'testKey',42 permission: {43 collectionAdmin: true,44 },45 }],46 });47 const token = await collection.mintToken(alice);4849 await collection.addAdmin(alice, {Ethereum: caller});5051 const address = helper.ethAddress.fromCollectionId(collection.collectionId);52 const contract = helper.ethNativeContract.collection(address, 'nft', caller);5354 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});5556 const [{value}] = await token.getProperties(['testKey']);57 expect(value).to.equal('testValue');58 });5960 itEth('Can be deleted', async({helper}) => {61 const caller = await helper.eth.createAccountWithBalance(donor);62 const collection = await helper.nft.mintCollection(alice, {63 tokenPrefix: 'ethp',64 tokenPropertyPermissions: [{65 key: 'testKey',66 permission: {67 mutable: true,68 collectionAdmin: true,69 },70 }],71 });7273 await collection.addAdmin(alice, {Ethereum: caller});7475 const token = await collection.mintToken(alice);76 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);7778 const address = helper.ethAddress.fromCollectionId(collection.collectionId);79 const contract = helper.ethNativeContract.collection(address, 'nft', caller);8081 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});8283 const result = await token.getProperties(['testKey']);84 expect(result.length).to.equal(0);85 });8687 itEth('Can be read', async({helper}) => {88 const caller = await helper.eth.createAccountWithBalance(donor);89 const collection = await helper.nft.mintCollection(alice, {90 tokenPrefix: 'ethp',91 tokenPropertyPermissions: [{92 key: 'testKey',93 permission: {94 collectionAdmin: true,95 },96 }],97 });98 const token = await collection.mintToken(alice);99 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);100101 const address = helper.ethAddress.fromCollectionId(collection.collectionId);102 const contract = helper.ethNativeContract.collection(address, 'nft', caller);103104 const value = await contract.methods.property(token.tokenId, 'testKey').call();105 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));106 });107});108109110type ElementOf<A> = A extends readonly (infer T)[] ? T : never;111function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {112 if(args.length === 0) {113 yield internalRest as any;114 return;115 }116 for(const value of args[0]) {117 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;118 }119}