git.delta.rocks / unique-network / refs/commits / 413ee1397f1d

difftreelog

source

tests/src/eth/tokenProperties.test.ts4.6 KiBsourcehistory
1import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess} from '../util/helpers';2import {cartesian, 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 token properties', () => {8  itWeb3('Can be reconfigured', async({web3, api, privateKeyWrapper}) => {9    const alice = privateKeyWrapper('//Alice');10    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);11    for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {12      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});13      await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});14      15      const address = collectionIdToAddress(collection);16      const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});17  18      await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});19  20      const state = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();21      expect(state).to.be.deep.equal({22        [web3.utils.toHex('testKey')]: {mutable, collectionAdmin, tokenOwner},23      });24    }25  });26  itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {27    const alice = privateKeyWrapper('//Alice');28    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);29    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});30    const token = await createItemExpectSuccess(alice, collection, 'NFT');3132    await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{33      key: 'testKey',34      permission: {35        collectionAdmin: true,36      },37    }]));3839    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});4041    const address = collectionIdToAddress(collection);42    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});4344    await contract.methods.setProperty(token, 'testKey', Buffer.from('testValue')).send({from: caller});4546    const [{value}] = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toHuman()! as any;47    expect(value).to.equal('testValue');48  });49  itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {50    const alice = privateKeyWrapper('//Alice');51    const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);52    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});53    const token = await createItemExpectSuccess(alice, collection, 'NFT');5455    await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{56      key: 'testKey',57      permission: {58        mutable: true,59        collectionAdmin: true,60      },61    }]));62    await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));6364    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});6566    const address = collectionIdToAddress(collection);67    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6869    await contract.methods.deleteProperty(token, 'testKey').send({from: caller});7071    const result = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toJSON()! as any;72    expect(result.length).to.equal(0);73  });74  itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {75    const alice = privateKeyWrapper('//Alice');76    const caller = createEthAccount(web3);77    const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});78    const token = await createItemExpectSuccess(alice, collection, 'NFT');7980    await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{81      key: 'testKey',82      permission: {83        collectionAdmin: true,84      },85    }]));86    await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));8788    const address = collectionIdToAddress(collection);89    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});9091    const value = await contract.methods.property(token, 'testKey').call();92    expect(value).to.equal(web3.utils.toHex('testValue'));93  });94});