git.delta.rocks / unique-network / refs/commits / 7523de2ff68e

difftreelog

source

tests/src/eth/collectionProperties.test.ts2.7 KiBsourcehistory
1import privateKey from '../substrate/privateKey';2import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers';3import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';4import nonFungibleAbi from './nonFungibleAbi.json';5import {expect} from 'chai';6import {executeTransaction} from '../substrate/substrate-api';78describe('EVM collection properties', () => {9  itWeb3('Can be set', async({web3, api}) => {10    const alice = privateKey('//Alice');11    const caller = await createEthAccountWithBalance(api, web3);12    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});1314    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});1516    const address = collectionIdToAddress(collection);17    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});1819    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2021    const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any;22    expect(value).to.equal('testValue');23  });24  itWeb3('Can be deleted', async({web3, api}) => {25    const alice = privateKey('//Alice');26    const caller = await createEthAccountWithBalance(api, web3);27    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});2829    await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));3031    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});3233    const address = collectionIdToAddress(collection);34    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});3536    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});3738    const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any;39    expect(result.length).to.equal(0);40  });41  itWeb3('Can be read', async({web3, api}) => {42    const alice = privateKey('//Alice');43    const caller = createEthAccount(web3);44    const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});4546    await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));4748    const address = collectionIdToAddress(collection);49    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});5051    const value = await contract.methods.collectionProperty('testKey').call();52    expect(value).to.equal(web3.utils.toHex('testValue'));53  });54});