1234567891011121314151617import {itEth, usingEthPlaygrounds, expect, cartesian} from './util/playgrounds';18import {IKeyringPair} from '@polkadot/types/types';1920describe('EVM token properties', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 [alice] = await helper.arrange.createAccounts([100n], donor);28 });29 });3031 itEth('Can be reconfigured', async({helper}) => {32 const caller = await helper.eth.createAccountWithBalance(donor);33 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {34 const collection = await helper.nft.mintCollection(alice);35 await collection.addAdmin(alice, {Ethereum: caller});36 37 const address = helper.ethAddress.fromCollectionId(collection.collectionId);38 const contract = helper.ethNativeContract.collection(address, 'nft', caller);39 40 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});41 42 expect(await collection.getPropertyPermissions()).to.be.deep.equal([{43 key: 'testKey',44 permission: {mutable, collectionAdmin, tokenOwner},45 }]);46 }47 });4849 itEth('Can be set', async({helper}) => {50 const caller = await helper.eth.createAccountWithBalance(donor);51 const collection = await helper.nft.mintCollection(alice);52 const token = await collection.mintToken(alice);5354 await collection.setTokenPropertyPermissions(alice, [{55 key: 'testKey',56 permission: {57 collectionAdmin: true,58 },59 }]);6061 await collection.addAdmin(alice, {Ethereum: caller});6263 const address = helper.ethAddress.fromCollectionId(collection.collectionId);64 const contract = helper.ethNativeContract.collection(address, 'nft', caller);6566 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});6768 const [{value}] = await token.getProperties(['testKey']);69 expect(value).to.equal('testValue');70 });7172 itEth('Can be deleted', async({helper}) => {73 const caller = await helper.eth.createAccountWithBalance(donor);74 const collection = await helper.nft.mintCollection(alice);75 const token = await collection.mintToken(alice);7677 await collection.setTokenPropertyPermissions(alice, [{78 key: 'testKey',79 permission: {80 mutable: true,81 collectionAdmin: true,82 },83 }]);84 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);8586 await collection.addAdmin(alice, {Ethereum: caller});8788 const address = helper.ethAddress.fromCollectionId(collection.collectionId);89 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9091 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});9293 const result = await token.getProperties(['testKey']);94 expect(result.length).to.equal(0);95 });9697 itEth('Can be read', async({helper}) => {98 const caller = helper.eth.createAccount();99 const collection = await helper.nft.mintCollection(alice);100 const token = await collection.mintToken(alice);101102 await collection.setTokenPropertyPermissions(alice, [{103 key: 'testKey',104 permission: {105 collectionAdmin: true,106 },107 }]);108 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);109110 const address = helper.ethAddress.fromCollectionId(collection.collectionId);111 const contract = helper.ethNativeContract.collection(address, 'nft', caller);112113 const value = await contract.methods.property(token.tokenId, 'testKey').call();114 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));115 });116});