git.delta.rocks / unique-network / refs/commits / bb64e8b60176

difftreelog

source

tests/src/eth/tokenProperties.test.ts4.4 KiBsourcehistory
1import privateKey from '../substrate/privateKey';2import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess} from '../util/helpers';3import {cartesian, 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 token properties', () => {9  itWeb3('Can be reconfigured', async({web3, api}) => {10    const alice = privateKey('//Alice');11    const caller = await createEthAccountWithBalance(api, web3);12    for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {13      const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});14      await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});15      16      const address = collectionIdToAddress(collection);17      const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});18  19      await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});20  21      const state = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();22      expect(state).to.be.deep.equal({23        [web3.utils.toHex('testKey')]: {mutable, collectionAdmin, tokenOwner},24      });25    }26  });27  itWeb3('Can be set', async({web3, api}) => {28    const alice = privateKey('//Alice');29    const caller = await createEthAccountWithBalance(api, web3);30    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});31    const token = await createItemExpectSuccess(alice, collection, 'NFT');3233    await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{34      key: 'testKey',35      permission: {36        collectionAdmin: true,37      },38    }]));3940    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});4142    const address = collectionIdToAddress(collection);43    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});4445    await contract.methods.setProperty(token, 'testKey', Buffer.from('testValue')).send({from: caller});4647    const [{value}] = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toHuman()! as any;48    expect(value).to.equal('testValue');49  });50  itWeb3('Can be deleted', async({web3, api}) => {51    const alice = privateKey('//Alice');52    const caller = await createEthAccountWithBalance(api, web3);53    const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});54    const token = await createItemExpectSuccess(alice, collection, 'NFT');5556    await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{57      key: 'testKey',58      permission: {59        mutable: true,60        collectionAdmin: true,61      },62    }]));63    await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));6465    await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});6667    const address = collectionIdToAddress(collection);68    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6970    await contract.methods.deleteProperty(token, 'testKey').send({from: caller});7172    const result = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toJSON()! as any;73    expect(result.length).to.equal(0);74  });75  itWeb3('Can be read', async({web3, api}) => {76    const alice = privateKey('//Alice');77    const caller = createEthAccount(web3);78    const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});79    const token = await createItemExpectSuccess(alice, collection, 'NFT');8081    await executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, [{82      key: 'testKey',83      permission: {84        collectionAdmin: true,85      },86    }]));87    await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));8889    const address = collectionIdToAddress(collection);90    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});9192    const value = await contract.methods.property(token, 'testKey').call();93    expect(value).to.equal(web3.utils.toHex('testValue'));94  });95});