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
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -4,9 +4,8 @@
 //
 
 import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';
+import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';
 import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
-import { evmToAddress } from '@polkadot/util-crypto';
 import nonFungibleAbi from './nonFungibleAbi.json';
 import { expect } from 'chai';
 import waitNewBlocks from '../substrate/wait-new-blocks';
@@ -106,7 +105,70 @@
       expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
     }
   });
+  itWeb3.only('Can perform mintBulk()', async ({ web3, api }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: { type: 'NFT' },
+    });
+    const alice = privateKey('//Alice');
+
+    const caller = await createEthAccountWithBalance(api, web3);
+    const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });
+    await submitTransactionAsync(alice, changeAdminTx);
+    const receiver = createEthAccount(web3);
 
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+
+    {
+      const nextTokenId = await contract.methods.nextTokenId().call();
+      expect(nextTokenId).to.be.equal('1');
+      const result = await contract.methods.mintBulkWithTokenURI(
+        receiver,
+        [
+          [nextTokenId, 'Test URI 0'],
+          [+nextTokenId + 1, 'Test URI 1'],
+          [+nextTokenId + 2, 'Test URI 2'],
+        ],
+      ).send({ from: caller });
+      const events = normalizeEvents(result.events);
+
+      expect(events).to.be.deep.equal([
+        {
+          address,
+          event: 'Transfer',
+          args: {
+            from: '0x0000000000000000000000000000000000000000',
+            to: receiver,
+            tokenId: nextTokenId,
+          },
+        },
+        {
+          address,
+          event: 'Transfer',
+          args: {
+            from: '0x0000000000000000000000000000000000000000',
+            to: receiver,
+            tokenId: String(+nextTokenId + 1),
+          },
+        },
+        {
+          address,
+          event: 'Transfer',
+          args: {
+            from: '0x0000000000000000000000000000000000000000',
+            to: receiver,
+            tokenId: String(+nextTokenId + 2),
+          },
+        },
+      ]);
+
+      await waitNewBlocks(api, 1);
+      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
+      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
+      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
+    }
+  });
+
   itWeb3('Can perform burn()', async ({ web3, api }) => {
     const collection = await createCollectionExpectSuccess({
       mode: {type: 'NFT'},
@@ -264,6 +326,41 @@
       expect(+balance).to.equal(1);
     }
   });
+
+  itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: { type: 'NFT' },
+    });
+    const alice = privateKey('//Alice');
+
+    const owner = await createEthAccountWithBalance(api, web3);
+
+    const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+    await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+    
+    expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
+  });
+
+  itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: { type: 'NFT' },
+    });
+    const alice = privateKey('//Alice');
+
+    const owner = await createEthAccountWithBalance(api, web3);
+
+    const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+    
+    expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: owner }));
+    await waitNewBlocks(api, 1);
+    expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203');
+  });
 });
 
 describe('NFT: Fees', () => {
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
50 "type": "event"50 "type": "event"
51 },51 },
52 {52 {
53 "anonymous": true,53 "anonymous": false,
54 "inputs": [],54 "inputs": [],
55 "name": "MintingFinished",55 "name": "MintingFinished",
56 "type": "event"56 "type": "event"
162 "stateMutability": "view",162 "stateMutability": "view",
163 "type": "function"163 "type": "function"
164 },164 },
165 {
166 "inputs": [
167 {
168 "internalType": "uint256",
169 "name": "tokenId",
170 "type": "uint256"
171 }
172 ],
173 "name": "getVariableMetadata",
174 "outputs": [
175 {
176 "internalType": "bytes",
177 "name": "",
178 "type": "bytes"
179 }
180 ],
181 "stateMutability": "view",
182 "type": "function"
183 },
165 {184 {
166 "inputs": [185 "inputs": [
167 {186 {
210 "stateMutability": "nonpayable",229 "stateMutability": "nonpayable",
211 "type": "function"230 "type": "function"
212 },231 },
232 {
233 "inputs": [
234 {
235 "internalType": "address",
236 "name": "to",
237 "type": "address"
238 },
239 {
240 "internalType": "uint256[]",
241 "name": "tokenIds",
242 "type": "uint256[]"
243 }
244 ],
245 "name": "mintBulk",
246 "outputs": [
247 {
248 "internalType": "bool",
249 "name": "",
250 "type": "bool"
251 }
252 ],
253 "stateMutability": "nonpayable",
254 "type": "function"
255 },
256 {
257 "inputs": [
258 {
259 "internalType": "address",
260 "name": "to",
261 "type": "address"
262 },
263 {
264 "components": [
265 {
266 "internalType": "uint256",
267 "name": "field_0",
268 "type": "uint256"
269 },
270 {
271 "internalType": "string",
272 "name": "field_1",
273 "type": "string"
274 }
275 ],
276 "internalType": "struct Tuple0[]",
277 "name": "tokens",
278 "type": "tuple[]"
279 }
280 ],
281 "name": "mintBulkWithTokenURI",
282 "outputs": [
283 {
284 "internalType": "bool",
285 "name": "",
286 "type": "bool"
287 }
288 ],
289 "stateMutability": "nonpayable",
290 "type": "function"
291 },
213 {292 {
214 "inputs": [293 "inputs": [
215 {294 {
224 },303 },
225 {304 {
226 "internalType": "string",305 "internalType": "string",
227 "name": "tokenURI",306 "name": "tokenUri",
228 "type": "string"307 "type": "string"
229 }308 }
230 ],309 ],
366 "stateMutability": "nonpayable",445 "stateMutability": "nonpayable",
367 "type": "function"446 "type": "function"
368 },447 },
448 {
449 "inputs": [
450 {
451 "internalType": "uint256",
452 "name": "tokenId",
453 "type": "uint256"
454 },
455 {
456 "internalType": "bytes",
457 "name": "data",
458 "type": "bytes"
459 }
460 ],
461 "name": "setVariableMetadata",
462 "outputs": [],
463 "stateMutability": "nonpayable",
464 "type": "function"
465 },
369 {466 {
370 "inputs": [467 "inputs": [
371 {468 {