difftreelog
refactor eth tokenProperties
in: master
1 file changed
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth1import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess} from '../util/helpers';2import {cartesian, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';1import {cartesian} from './util/helpers';3import nonFungibleAbi from './nonFungibleAbi.json';4import {expect} from 'chai';2import {itEth, expect} from '../eth/util/playgrounds';5import {executeTransaction} from '../substrate/substrate-api';637describe('EVM token properties', () => {4describe.only('EVM token properties', () => {8 itWeb3('Can be reconfigured', async({web3, api, privateKeyWrapper}) => {5 itEth('Can be reconfigured', async({helper, privateKey}) => {9 const alice = privateKeyWrapper('//Alice');6 const alice = privateKey('//Alice');10 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);7 const caller = await helper.eth.createAccountWithBalance(alice);811 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {9 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {12 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});10 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});13 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});11 await collection.addAdmin(alice, {Ethereum: caller});14 1215 const address = collectionIdToAddress(collection);13 const address = helper.ethAddress.fromCollectionId(collection.collectionId);16 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});14 const contract = await helper.ethNativeContract.collection(address, 'nft', caller);17 1518 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});16 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});19 17 20 const state = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();18 const state = await collection.getPropertyPermissions();21 expect(state).to.be.deep.equal({19 expect(state).to.be.deep.equal([{22 [web3.utils.toHex('testKey')]: {mutable, collectionAdmin, tokenOwner},20 key: 'testKey',21 permission: {mutable, collectionAdmin, tokenOwner},23 });22 }]);24 }23 }25 });24 });2526 itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {26 itEth('Can be set', async({helper, privateKey}) => {27 const alice = privateKeyWrapper('//Alice');27 const alice = privateKey('//Alice');28 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);28 const caller = await helper.eth.createAccountWithBalance(alice);29 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});29 const collection = await helper.nft.mintCollection(alice, {30 const token = await createItemExpectSuccess(alice, collection, 'NFT');3132 await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{30 tokenPrefix: 'ethp',31 tokenPropertyPermissions: [{33 key: 'testKey',32 key: 'testKey',34 permission: {33 permission: {35 collectionAdmin: true,34 collectionAdmin: true,36 },35 },37 }]));36 }],37 });38 const token = await collection.mintToken(alice);383939 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});40 await collection.addAdmin(alice, {Ethereum: caller});404141 const address = collectionIdToAddress(collection);42 const address = helper.ethAddress.fromCollectionId(collection.collectionId);42 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});43 const contract = helper.ethNativeContract.collection(address, 'nft', caller);434444 await contract.methods.setProperty(token, 'testKey', Buffer.from('testValue')).send({from: caller});45 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});454646 const [{value}] = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toHuman()! as any;47 const [{value}] = await token.getProperties(['testKey']);47 expect(value).to.equal('testValue');48 expect(value).to.equal('testValue');48 });49 });5049 itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {51 itEth('Can be deleted', async({helper, privateKey}) => {50 const alice = privateKeyWrapper('//Alice');52 const alice = privateKey('//Alice');51 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);53 const caller = await helper.eth.createAccountWithBalance(alice);52 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});54 const collection = await helper.nft.mintCollection(alice, {53 const token = await createItemExpectSuccess(alice, collection, 'NFT');5455 await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{55 tokenPrefix: 'ethp',56 tokenPropertyPermissions: [{56 key: 'testKey',57 key: 'testKey',57 permission: {58 permission: {58 mutable: true,59 mutable: true,59 collectionAdmin: true,60 collectionAdmin: true,60 },61 },61 }]));62 }],63 });6462 await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));65 await collection.addAdmin(alice, {Ethereum: caller});636667 const token = await collection.mintToken(alice);64 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});68 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);656966 const address = collectionIdToAddress(collection);70 const address = helper.ethAddress.fromCollectionId(collection.collectionId);67 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});71 const contract = helper.ethNativeContract.collection(address, 'nft', caller);687269 await contract.methods.deleteProperty(token, 'testKey').send({from: caller});73 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});707471 const result = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toJSON()! as any;75 const result = await token.getProperties(['testKey']);72 expect(result.length).to.equal(0);76 expect(result.length).to.equal(0);73 });77 });7874 itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {79 itEth('Can be read', async({helper, privateKey}) => {75 const alice = privateKeyWrapper('//Alice');80 const alice = privateKey('//Alice');76 const caller = createEthAccount(web3);77 const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});81 const caller = await helper.eth.createAccountWithBalance(alice);78 const token = await createItemExpectSuccess(alice, collection, 'NFT');82 const collection = await helper.nft.mintCollection(alice, {7980 await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{83 tokenPrefix: 'ethp',84 tokenPropertyPermissions: [{81 key: 'testKey',85 key: 'testKey',82 permission: {86 permission: {83 collectionAdmin: true,87 collectionAdmin: true,84 },88 },85 }]));89 }],90 });91 const token = await collection.mintToken(alice);86 await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));92 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);879388 const address = collectionIdToAddress(collection);94 const address = helper.ethAddress.fromCollectionId(collection.collectionId);89 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});95 const contract = helper.ethNativeContract.collection(address, 'nft', caller);909691 const value = await contract.methods.property(token, 'testKey').call();97 const value = await contract.methods.property(token.tokenId, 'testKey').call();92 expect(value).to.equal(web3.utils.toHex('testValue'));98 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));93 });99 });94});100});95101