1import {cartesian} from './util/helpers';2import {itEth, expect} from '../eth/util/playgrounds';34describe('EVM token properties', () => {5 itEth('Can be reconfigured', async({helper, privateKey}) => {6 const alice = privateKey('//Alice');7 const caller = await helper.eth.createAccountWithBalance(alice);89 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {10 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});11 await collection.addAdmin(alice, {Ethereum: caller});1213 const address = helper.ethAddress.fromCollectionId(collection.collectionId);14 const contract = helper.ethNativeContract.collection(address, 'nft', caller);1516 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});17 18 const state = await collection.getPropertyPermissions();19 expect(state).to.be.deep.equal([{20 key: 'testKey',21 permission: {mutable, collectionAdmin, tokenOwner},22 }]);23 }24 });2526 itEth('Can be set', async({helper, privateKey}) => {27 const alice = privateKey('//Alice');28 const caller = await helper.eth.createAccountWithBalance(alice);29 const collection = await helper.nft.mintCollection(alice, {30 tokenPrefix: 'ethp',31 tokenPropertyPermissions: [{32 key: 'testKey',33 permission: {34 collectionAdmin: true,35 },36 }],37 });38 const token = await collection.mintToken(alice);3940 await collection.addAdmin(alice, {Ethereum: caller});4142 const address = helper.ethAddress.fromCollectionId(collection.collectionId);43 const contract = helper.ethNativeContract.collection(address, 'nft', caller);4445 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});4647 const [{value}] = await token.getProperties(['testKey']);48 expect(value).to.equal('testValue');49 });5051 itEth('Can be deleted', async({helper, privateKey}) => {52 const alice = privateKey('//Alice');53 const caller = await helper.eth.createAccountWithBalance(alice);54 const collection = await helper.nft.mintCollection(alice, {55 tokenPrefix: 'ethp',56 tokenPropertyPermissions: [{57 key: 'testKey',58 permission: {59 mutable: true,60 collectionAdmin: true,61 },62 }],63 });6465 await collection.addAdmin(alice, {Ethereum: caller});6667 const token = await collection.mintToken(alice);68 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);6970 const address = helper.ethAddress.fromCollectionId(collection.collectionId);71 const contract = helper.ethNativeContract.collection(address, 'nft', caller);7273 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});7475 const result = await token.getProperties(['testKey']);76 expect(result.length).to.equal(0);77 });7879 itEth('Can be read', async({helper, privateKey}) => {80 const alice = privateKey('//Alice');81 const caller = await helper.eth.createAccountWithBalance(alice);82 const collection = await helper.nft.mintCollection(alice, {83 tokenPrefix: 'ethp',84 tokenPropertyPermissions: [{85 key: 'testKey',86 permission: {87 collectionAdmin: true,88 },89 }],90 });91 const token = await collection.mintToken(alice);92 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);9394 const address = helper.ethAddress.fromCollectionId(collection.collectionId);95 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9697 const value = await contract.methods.property(token.tokenId, 'testKey').call();98 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));99 });100});