1import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers';2import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';3import nonFungibleAbi from './nonFungibleAbi.json';4import {expect} from 'chai';5import {executeTransaction} from '../substrate/substrate-api';67describe('EVM collection properties', () => {8 itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {9 const alice = privateKeyWrapper('//Alice');10 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);11 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});1213 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});1415 const address = collectionIdToAddress(collection);16 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});1718 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});1920 const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any;21 expect(value).to.equal('testValue');22 });23 itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {24 const alice = privateKeyWrapper('//Alice');25 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);26 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});2728 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));2930 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});3132 const address = collectionIdToAddress(collection);33 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});3435 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});3637 const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any;38 expect(result.length).to.equal(0);39 });40 itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {41 const alice = privateKeyWrapper('//Alice');42 const caller = createEthAccount(web3);43 const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});4445 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));4647 const address = collectionIdToAddress(collection);48 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});4950 const value = await contract.methods.collectionProperty('testKey').call();51 expect(value).to.equal(web3.utils.toHex('testValue'));52 });53});