git.delta.rocks / unique-network / refs/commits / 09dc1ff93b78

difftreelog

refactor eth tokenProperties

Daniel Shiposha2022-09-29parent: #ab38216.patch.diff
in: master

1 file changed

modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
1import {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';
63
7describe('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);
8
11 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 12
15 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 15
18 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 });
25
26 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');
31
32 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);
3839
39 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});40 await collection.addAdmin(alice, {Ethereum: caller});
4041
41 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);
4344
44 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});
4546
46 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 });
50
49 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');
54
55 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 });
64
62 await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));65 await collection.addAdmin(alice, {Ethereum: caller});
6366
67 const token = await collection.mintToken(alice);
64 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});68 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
6569
66 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);
6872
69 await contract.methods.deleteProperty(token, 'testKey').send({from: caller});73 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});
7074
71 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 });
78
74 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, {
79
80 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'}]);
8793
88 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);
9096
91 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