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';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});1import {cartesian} from './util/helpers';2import {itEth, expect} from '../eth/util/playgrounds';34describe.only('EVM token properties', () => {5 itEth('Can be reconfigured', async({helper, privateKey}) => {6 const alice = privateKey('//Alice');7 const caller = await helper.eth.createAccountWithBalance(alice);89 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {10 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});11 await collection.addAdmin(alice, {Ethereum: caller});1213 const address = helper.ethAddress.fromCollectionId(collection.collectionId);14 const contract = await helper.ethNativeContract.collection(address, 'nft', caller);1516 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});17 18 const state = await collection.getPropertyPermissions();19 expect(state).to.be.deep.equal([{20 key: 'testKey',21 permission: {mutable, collectionAdmin, tokenOwner},22 }]);23 }24 });2526 itEth('Can be set', async({helper, privateKey}) => {27 const alice = privateKey('//Alice');28 const caller = await helper.eth.createAccountWithBalance(alice);29 const collection = await helper.nft.mintCollection(alice, {30 tokenPrefix: 'ethp',31 tokenPropertyPermissions: [{32 key: 'testKey',33 permission: {34 collectionAdmin: true,35 },36 }],37 });38 const token = await collection.mintToken(alice);3940 await collection.addAdmin(alice, {Ethereum: caller});4142 const address = helper.ethAddress.fromCollectionId(collection.collectionId);43 const contract = helper.ethNativeContract.collection(address, 'nft', caller);4445 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});4647 const [{value}] = await token.getProperties(['testKey']);48 expect(value).to.equal('testValue');49 });5051 itEth('Can be deleted', async({helper, privateKey}) => {52 const alice = privateKey('//Alice');53 const caller = await helper.eth.createAccountWithBalance(alice);54 const collection = await helper.nft.mintCollection(alice, {55 tokenPrefix: 'ethp',56 tokenPropertyPermissions: [{57 key: 'testKey',58 permission: {59 mutable: true,60 collectionAdmin: true,61 },62 }],63 });6465 await collection.addAdmin(alice, {Ethereum: caller});6667 const token = await collection.mintToken(alice);68 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);6970 const address = helper.ethAddress.fromCollectionId(collection.collectionId);71 const contract = helper.ethNativeContract.collection(address, 'nft', caller);7273 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});7475 const result = await token.getProperties(['testKey']);76 expect(result.length).to.equal(0);77 });7879 itEth('Can be read', async({helper, privateKey}) => {80 const alice = privateKey('//Alice');81 const caller = await helper.eth.createAccountWithBalance(alice);82 const collection = await helper.nft.mintCollection(alice, {83 tokenPrefix: 'ethp',84 tokenPropertyPermissions: [{85 key: 'testKey',86 permission: {87 collectionAdmin: true,88 },89 }],90 });91 const token = await collection.mintToken(alice);92 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);9394 const address = helper.ethAddress.fromCollectionId(collection.collectionId);95 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9697 const value = await contract.methods.property(token.tokenId, 'testKey').call();98 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));99 });100});