git.delta.rocks / unique-network / refs/commits / 95c88d307c6b

difftreelog

eth/collectionProperties migrated

rkv2022-09-28parent: #f0eacde.patch.diff
in: master

1 file changed

modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
1import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers';
2import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
3import nonFungibleAbi from './nonFungibleAbi.json';
4import {expect} from 'chai';
5import {executeTransaction} from '../substrate/substrate-api';2import {IKeyringPair} from '@polkadot/types/types';
63
7describe('EVM collection properties', () => {4describe('EVM collection properties', () => {
5 let donor: IKeyringPair;
6 let alice: IKeyringPair;
7
8 before(async function() {
9 await usingEthPlaygrounds(async (_helper, privateKey) => {
10 donor = privateKey('//Alice');
11 [alice] = await _helper.arrange.createAccounts([10n], donor);
12 });
13 });
14
8 itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {15 itEth('Can be set', async({helper}) => {
9 const alice = privateKeyWrapper('//Alice');
10 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);16 const caller = await helper.eth.createAccountWithBalance(donor);
11 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});17 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});
12
13 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});18 await collection.addAdmin(alice, {Ethereum: caller});
1419
15 const address = collectionIdToAddress(collection);20 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
16 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});21 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
1722
18 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});23 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});
1924
20 const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any;25 const raw = (await collection.getData())?.raw;
26
21 expect(value).to.equal('testValue');27 expect(raw.properties[0].value).to.equal('testValue');
22 });28 });
29
23 itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {30 itEth('Can be deleted', async({helper}) => {
24 const alice = privateKeyWrapper('//Alice');
25 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);31 const caller = await helper.eth.createAccountWithBalance(donor);
26 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});32 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});
27
28 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));
2933
30 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});34 await collection.addAdmin(alice, {Ethereum: caller});
3135
32 const address = collectionIdToAddress(collection);36 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
33 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});37 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
3438
35 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});39 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});
3640
37 const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any;41 const raw = (await collection.getData())?.raw;
42
38 expect(result.length).to.equal(0);43 expect(raw.properties.length).to.equal(0);
39 });44 });
45
40 itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {46 itEth('Can be read', async({helper}) => {
41 const alice = privateKeyWrapper('//Alice');
42 const caller = createEthAccount(web3);47 const caller = helper.eth.createAccount();
43 const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});48 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});
44
45 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));
4649
47 const address = collectionIdToAddress(collection);50 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
48 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});51 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
4952
50 const value = await contract.methods.collectionProperty('testKey').call();53 const value = await contract.methods.collectionProperty('testKey').call();
51 expect(value).to.equal(web3.utils.toHex('testValue'));54 expect(value).to.equal(helper.web3?.utils.toHex('testValue'));
52 });55 });
53});56});
5457