git.delta.rocks / unique-network / refs/commits / 36c7382c2750

difftreelog

test mintBulk/metadata api

Yaroslav Bolyukin2021-09-01parent: #ac37b71.patch.diff
in: master

2 files changed

modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
4//4//
55
6import privateKey from '../substrate/privateKey';6import privateKey from '../substrate/privateKey';
7import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';7import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';
8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
9import { evmToAddress } from '@polkadot/util-crypto';
10import nonFungibleAbi from './nonFungibleAbi.json';9import nonFungibleAbi from './nonFungibleAbi.json';
11import { expect } from 'chai';10import { expect } from 'chai';
12import waitNewBlocks from '../substrate/wait-new-blocks';11import waitNewBlocks from '../substrate/wait-new-blocks';
106 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');105 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
107 }106 }
108 });107 });
108 itWeb3.only('Can perform mintBulk()', async ({ web3, api }) => {
109 const collection = await createCollectionExpectSuccess({
110 mode: { type: 'NFT' },
111 });
112 const alice = privateKey('//Alice');
113
114 const caller = await createEthAccountWithBalance(api, web3);
115 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });
116 await submitTransactionAsync(alice, changeAdminTx);
117 const receiver = createEthAccount(web3);
118
119 const address = collectionIdToAddress(collection);
120 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
121
122 {
123 const nextTokenId = await contract.methods.nextTokenId().call();
124 expect(nextTokenId).to.be.equal('1');
125 const result = await contract.methods.mintBulkWithTokenURI(
126 receiver,
127 [
128 [nextTokenId, 'Test URI 0'],
129 [+nextTokenId + 1, 'Test URI 1'],
130 [+nextTokenId + 2, 'Test URI 2'],
131 ],
132 ).send({ from: caller });
133 const events = normalizeEvents(result.events);
134
135 expect(events).to.be.deep.equal([
136 {
137 address,
138 event: 'Transfer',
139 args: {
140 from: '0x0000000000000000000000000000000000000000',
141 to: receiver,
142 tokenId: nextTokenId,
143 },
144 },
145 {
146 address,
147 event: 'Transfer',
148 args: {
149 from: '0x0000000000000000000000000000000000000000',
150 to: receiver,
151 tokenId: String(+nextTokenId + 1),
152 },
153 },
154 {
155 address,
156 event: 'Transfer',
157 args: {
158 from: '0x0000000000000000000000000000000000000000',
159 to: receiver,
160 tokenId: String(+nextTokenId + 2),
161 },
162 },
163 ]);
164
165 await waitNewBlocks(api, 1);
166 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
167 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
168 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
169 }
170 });
109171
110 itWeb3('Can perform burn()', async ({ web3, api }) => {172 itWeb3('Can perform burn()', async ({ web3, api }) => {
111 const collection = await createCollectionExpectSuccess({173 const collection = await createCollectionExpectSuccess({
265 }327 }
266 });328 });
329
330 itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => {
331 const collection = await createCollectionExpectSuccess({
332 mode: { type: 'NFT' },
333 });
334 const alice = privateKey('//Alice');
335
336 const owner = await createEthAccountWithBalance(api, web3);
337
338 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
339 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
340
341 const address = collectionIdToAddress(collection);
342 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
343
344 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
345 });
346
347 itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => {
348 const collection = await createCollectionExpectSuccess({
349 mode: { type: 'NFT' },
350 });
351 const alice = privateKey('//Alice');
352
353 const owner = await createEthAccountWithBalance(api, web3);
354
355 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
356
357 const address = collectionIdToAddress(collection);
358 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
359
360 expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: owner }));
361 await waitNewBlocks(api, 1);
362 expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
363 });
267});364});
268365
269describe('NFT: Fees', () => {366describe('NFT: Fees', () => {
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -50,7 +50,7 @@
         "type": "event"
     },
     {
-        "anonymous": true,
+        "anonymous": false,
         "inputs": [],
         "name": "MintingFinished",
         "type": "event"
@@ -165,6 +165,25 @@
     {
         "inputs": [
             {
+                "internalType": "uint256",
+                "name": "tokenId",
+                "type": "uint256"
+            }
+        ],
+        "name": "getVariableMetadata",
+        "outputs": [
+            {
+                "internalType": "bytes",
+                "name": "",
+                "type": "bytes"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
                 "internalType": "address",
                 "name": "owner",
                 "type": "address"
@@ -218,13 +237,73 @@
                 "type": "address"
             },
             {
+                "internalType": "uint256[]",
+                "name": "tokenIds",
+                "type": "uint256[]"
+            }
+        ],
+        "name": "mintBulk",
+        "outputs": [
+            {
+                "internalType": "bool",
+                "name": "",
+                "type": "bool"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "components": [
+                    {
+                        "internalType": "uint256",
+                        "name": "field_0",
+                        "type": "uint256"
+                    },
+                    {
+                        "internalType": "string",
+                        "name": "field_1",
+                        "type": "string"
+                    }
+                ],
+                "internalType": "struct Tuple0[]",
+                "name": "tokens",
+                "type": "tuple[]"
+            }
+        ],
+        "name": "mintBulkWithTokenURI",
+        "outputs": [
+            {
+                "internalType": "bool",
+                "name": "",
+                "type": "bool"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
                 "internalType": "uint256",
                 "name": "tokenId",
                 "type": "uint256"
             },
             {
                 "internalType": "string",
-                "name": "tokenURI",
+                "name": "tokenUri",
                 "type": "string"
             }
         ],
@@ -369,6 +448,24 @@
     {
         "inputs": [
             {
+                "internalType": "uint256",
+                "name": "tokenId",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bytes",
+                "name": "data",
+                "type": "bytes"
+            }
+        ],
+        "name": "setVariableMetadata",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
                 "internalType": "uint32",
                 "name": "interfaceId",
                 "type": "uint32"
@@ -514,4 +611,4 @@
         "stateMutability": "nonpayable",
         "type": "function"
     }
-]
\ No newline at end of file
+]