git.delta.rocks / unique-network / refs/commits / 7d316fa0c4f8

difftreelog

test burn/mint

Yaroslav Bolyukin2021-08-11parent: #c535db9.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,11 +4,13 @@
 //
 
 import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
+import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
 import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, 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';
+import { submitTransactionAsync } from '../substrate/substrate-api';
 
 describe('NFT: Information getting', () => {
   itWeb3('totalSupply', async ({ api, web3 }) => {
@@ -64,6 +66,78 @@
 });
 
 describe('NFT: Plain calls', () => {
+  itWeb3('Can perform mint()', 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.mintWithTokenURI(
+        receiver,
+        nextTokenId,
+        'Test URI',
+      ).send({from: caller});
+      const events = normalizeEvents(result.events);
+
+      expect(events).to.be.deep.equal([
+        {
+          address,
+          event: 'Transfer',
+          args: {
+            from: '0x0000000000000000000000000000000000000000',
+            to: receiver,
+            tokenId: nextTokenId,
+          },
+        },
+      ]);
+
+      await waitNewBlocks(api, 1);
+      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+    }
+  });
+
+  itWeb3('Can perform burn()', async ({ web3, api }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: {type: 'NFT'},
+    });
+    const alice = privateKey('//Alice');
+
+    const owner = await createEthAccountWithBalance(api, web3);
+
+    const tokenId = 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});
+
+    {
+      const result = await contract.methods.burn(tokenId).send({ from: owner });
+      const events = normalizeEvents(result.events);
+      
+      expect(events).to.be.deep.equal([
+        {
+          address,
+          event: 'Transfer',
+          args: {
+            from: owner,
+            to: '0x0000000000000000000000000000000000000000',
+            tokenId: tokenId.toString(),
+          },
+        },
+      ]);
+    }
+  });
+
   itWeb3('Can perform approve()', async ({ web3, api }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
@@ -193,6 +267,60 @@
 });
 
 describe('NFT: Substrate calls', () => {
+  itWeb3('Events emitted for mint()', async ({ web3 }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: { type: 'NFT' },
+    });
+    const alice = privateKey('//Alice');
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+
+    let tokenId: number;
+    const events = await recordEvents(contract, async () => {
+      tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+    });
+
+    expect(events).to.be.deep.equal([
+      {
+        address,
+        event: 'Transfer',
+        args: {
+          from: '0x0000000000000000000000000000000000000000',
+          to: subToEth(alice.address),
+          tokenId: tokenId!.toString(),
+        },
+      },
+    ]);
+  });
+
+  itWeb3('Events emitted for burn()', async ({ web3 }) => {
+    const collection = await createCollectionExpectSuccess({
+      mode: { type: 'NFT' },
+    });
+    const alice = privateKey('//Alice');
+
+    const address = collectionIdToAddress(collection);
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+
+    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+    const events = await recordEvents(contract, async () => {
+      await burnItemExpectSuccess(alice, collection, tokenId);
+    });
+
+    expect(events).to.be.deep.equal([
+      {
+        address,
+        event: 'Transfer',
+        args: {
+          from: subToEth(alice.address),
+          to: '0x0000000000000000000000000000000000000000',
+          tokenId: tokenId.toString(),
+        },
+      },
+    ]);
+  });
+
   itWeb3('Events emitted for approve()', async ({ web3 }) => {
     const collection = await createCollectionExpectSuccess({
       mode: { type: 'NFT' },
@@ -284,4 +412,4 @@
       },
     ]);
   });
-});
\ No newline at end of file
+});
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
49 "name": "ApprovalForAll",49 "name": "ApprovalForAll",
50 "type": "event"50 "type": "event"
51 },51 },
52 {
53 "anonymous": true,
54 "inputs": [],
55 "name": "MintingFinished",
56 "type": "event"
57 },
52 {58 {
53 "anonymous": false,59 "anonymous": false,
54 "inputs": [60 "inputs": [
89 ],95 ],
90 "name": "approve",96 "name": "approve",
91 "outputs": [],97 "outputs": [],
92 "stateMutability": "payable",98 "stateMutability": "nonpayable",
93 "type": "function"99 "type": "function"
94 },100 },
95 {101 {
111 "stateMutability": "view",117 "stateMutability": "view",
112 "type": "function"118 "type": "function"
113 },119 },
120 {
121 "inputs": [
122 {
123 "internalType": "uint256",
124 "name": "tokenId",
125 "type": "uint256"
126 }
127 ],
128 "name": "burn",
129 "outputs": [],
130 "stateMutability": "nonpayable",
131 "type": "function"
132 },
133 {
134 "inputs": [],
135 "name": "finishMinting",
136 "outputs": [
137 {
138 "internalType": "bool",
139 "name": "",
140 "type": "bool"
141 }
142 ],
143 "stateMutability": "nonpayable",
144 "type": "function"
145 },
114 {146 {
115 "inputs": [147 "inputs": [
116 {148 {
130 "stateMutability": "view",162 "stateMutability": "view",
131 "type": "function"163 "type": "function"
132 },164 },
133 {165 {
134 "inputs": [166 "inputs": [
135 {167 {
136 "internalType": "address",168 "internalType": "address",
144 }176 }
145 ],177 ],
146 "name": "isApprovedForAll",178 "name": "isApprovedForAll",
179 "outputs": [
180 {
181 "internalType": "address",
182 "name": "",
183 "type": "address"
184 }
185 ],
186 "stateMutability": "view",
187 "type": "function"
188 },
189 {
190 "inputs": [
191 {
192 "internalType": "address",
193 "name": "to",
194 "type": "address"
195 },
196 {
197 "internalType": "uint256",
198 "name": "tokenId",
199 "type": "uint256"
200 }
201 ],
202 "name": "mint",
147 "outputs": [203 "outputs": [
148 {204 {
149 "internalType": "bool",205 "internalType": "bool",
150 "name": "",206 "name": "",
151 "type": "bool"207 "type": "bool"
152 }208 }
153 ],209 ],
210 "stateMutability": "nonpayable",
211 "type": "function"
212 },
213 {
214 "inputs": [
215 {
216 "internalType": "address",
217 "name": "to",
218 "type": "address"
219 },
220 {
221 "internalType": "uint256",
222 "name": "tokenId",
223 "type": "uint256"
224 },
225 {
226 "internalType": "string",
227 "name": "tokenURI",
228 "type": "string"
229 }
230 ],
231 "name": "mintWithTokenURI",
232 "outputs": [
233 {
234 "internalType": "bool",
235 "name": "",
236 "type": "bool"
237 }
238 ],
239 "stateMutability": "nonpayable",
240 "type": "function"
241 },
242 {
243 "inputs": [],
244 "name": "mintingFinished",
245 "outputs": [
246 {
247 "internalType": "bool",
248 "name": "",
249 "type": "bool"
250 }
251 ],
154 "stateMutability": "view",252 "stateMutability": "view",
155 "type": "function"253 "type": "function"
156 },254 },
157 {255 {
158 "inputs": [],256 "inputs": [],
159 "name": "name",257 "name": "name",
160 "outputs": [258 "outputs": [
161 {259 {
162 "internalType": "string",260 "internalType": "string",
163 "name": "res_name",261 "name": "",
164 "type": "string"262 "type": "string"
165 }263 }
166 ],264 ],
167 "stateMutability": "view",265 "stateMutability": "view",
168 "type": "function"266 "type": "function"
169 },267 },
268 {
269 "inputs": [],
270 "name": "nextTokenId",
271 "outputs": [
272 {
273 "internalType": "uint256",
274 "name": "",
275 "type": "uint256"
276 }
277 ],
278 "stateMutability": "view",
279 "type": "function"
280 },
170 {281 {
171 "inputs": [282 "inputs": [
172 {283 {
206 ],317 ],
207 "name": "safeTransferFrom",318 "name": "safeTransferFrom",
208 "outputs": [],319 "outputs": [],
209 "stateMutability": "payable",320 "stateMutability": "nonpayable",
210 "type": "function"321 "type": "function"
211 },322 },
212 {323 {
232 "type": "bytes"343 "type": "bytes"
233 }344 }
234 ],345 ],
235 "name": "safeTransferFrom",346 "name": "safeTransferFromWithData",
236 "outputs": [],347 "outputs": [],
237 "stateMutability": "payable",348 "stateMutability": "nonpayable",
238 "type": "function"349 "type": "function"
239 },350 },
240 {351 {
258 {369 {
259 "inputs": [370 "inputs": [
260 {371 {
261 "internalType": "bytes4",372 "internalType": "uint32",
262 "name": "interfaceID",373 "name": "interfaceId",
263 "type": "bytes4"374 "type": "uint32"
264 }375 }
265 ],376 ],
266 "name": "supportsInterface",377 "name": "supportsInterface",
271 "type": "bool"382 "type": "bool"
272 }383 }
273 ],384 ],
274 "stateMutability": "pure",385 "stateMutability": "view",
275 "type": "function"386 "type": "function"
276 },387 },
277 {388 {
280 "outputs": [391 "outputs": [
281 {392 {
282 "internalType": "string",393 "internalType": "string",
283 "name": "res_symbol",394 "name": "",
284 "type": "string"395 "type": "string"
285 }396 }
286 ],397 ],
364 },475 },
365 {476 {
366 "inputs": [477 "inputs": [
367 {
368 "internalType": "address",
369 "name": "from",
370 "type": "address"
371 },
372 {478 {
373 "internalType": "address",479 "internalType": "address",
374 "name": "to",480 "name": "to",
380 "type": "uint256"486 "type": "uint256"
381 }487 }
382 ],488 ],
383 "name": "transferFrom",489 "name": "transfer",
384 "outputs": [],490 "outputs": [],
385 "stateMutability": "payable",491 "stateMutability": "nonpayable",
386 "type": "function"492 "type": "function"
387 },493 },
388 {494 {
389 "inputs": [495 "inputs": [
496 {
497 "internalType": "address",
498 "name": "from",
499 "type": "address"
500 },
390 {501 {
391 "internalType": "address",502 "internalType": "address",
392 "name": "to",503 "name": "to",
398 "type": "uint256"509 "type": "uint256"
399 }510 }
400 ],511 ],
401 "name": "transfer",512 "name": "transferFrom",
402 "outputs": [],513 "outputs": [],
403 "stateMutability": "payable",514 "stateMutability": "nonpayable",
404 "type": "function"515 "type": "function"
405 }516 }
406]517]