difftreelog
test burn/mint
in: master
2 files changed
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth4//4//556import privateKey from '../substrate/privateKey';6import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';7import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import { evmToAddress } from '@polkadot/util-crypto';9import nonFungibleAbi from './nonFungibleAbi.json';10import nonFungibleAbi from './nonFungibleAbi.json';10import { expect } from 'chai';11import { expect } from 'chai';11import waitNewBlocks from '../substrate/wait-new-blocks';12import waitNewBlocks from '../substrate/wait-new-blocks';13import { submitTransactionAsync } from '../substrate/substrate-api';121413describe('NFT: Information getting', () => {15describe('NFT: Information getting', () => {14 itWeb3('totalSupply', async ({ api, web3 }) => {16 itWeb3('totalSupply', async ({ api, web3 }) => {64});66});656766describe('NFT: Plain calls', () => {68describe('NFT: Plain calls', () => {69 itWeb3('Can perform mint()', async ({ web3, api }) => {70 const collection = await createCollectionExpectSuccess({71 mode: { type: 'NFT' },72 });73 const alice = privateKey('//Alice');7475 const caller = await createEthAccountWithBalance(api, web3);76 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });77 await submitTransactionAsync(alice, changeAdminTx);78 const receiver = createEthAccount(web3);7980 const address = collectionIdToAddress(collection);81 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});8283 {84 const nextTokenId = await contract.methods.nextTokenId().call();85 expect(nextTokenId).to.be.equal('1');86 const result = await contract.methods.mintWithTokenURI(87 receiver,88 nextTokenId,89 'Test URI',90 ).send({from: caller});91 const events = normalizeEvents(result.events);9293 expect(events).to.be.deep.equal([94 {95 address,96 event: 'Transfer',97 args: {98 from: '0x0000000000000000000000000000000000000000',99 to: receiver,100 tokenId: nextTokenId,101 },102 },103 ]);104105 await waitNewBlocks(api, 1);106 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');107 }108 });109110 itWeb3('Can perform burn()', async ({ web3, api }) => {111 const collection = await createCollectionExpectSuccess({112 mode: {type: 'NFT'},113 });114 const alice = privateKey('//Alice');115116 const owner = await createEthAccountWithBalance(api, web3);117118 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });119 120 const address = collectionIdToAddress(collection);121 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});122123 {124 const result = await contract.methods.burn(tokenId).send({ from: owner });125 const events = normalizeEvents(result.events);126 127 expect(events).to.be.deep.equal([128 {129 address,130 event: 'Transfer',131 args: {132 from: owner,133 to: '0x0000000000000000000000000000000000000000',134 tokenId: tokenId.toString(),135 },136 },137 ]);138 }139 });14067 itWeb3('Can perform approve()', async ({ web3, api }) => {141 itWeb3('Can perform approve()', async ({ web3, api }) => {68 const collection = await createCollectionExpectSuccess({142 const collection = await createCollectionExpectSuccess({193});267});194268195describe('NFT: Substrate calls', () => {269describe('NFT: Substrate calls', () => {270 itWeb3('Events emitted for mint()', async ({ web3 }) => {271 const collection = await createCollectionExpectSuccess({272 mode: { type: 'NFT' },273 });274 const alice = privateKey('//Alice');275276 const address = collectionIdToAddress(collection);277 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);278279 let tokenId: number;280 const events = await recordEvents(contract, async () => {281 tokenId = await createItemExpectSuccess(alice, collection, 'NFT');282 });283284 expect(events).to.be.deep.equal([285 {286 address,287 event: 'Transfer',288 args: {289 from: '0x0000000000000000000000000000000000000000',290 to: subToEth(alice.address),291 tokenId: tokenId!.toString(),292 },293 },294 ]);295 });296297 itWeb3('Events emitted for burn()', async ({ web3 }) => {298 const collection = await createCollectionExpectSuccess({299 mode: { type: 'NFT' },300 });301 const alice = privateKey('//Alice');302303 const address = collectionIdToAddress(collection);304 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);305306 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');307 const events = await recordEvents(contract, async () => {308 await burnItemExpectSuccess(alice, collection, tokenId);309 });310311 expect(events).to.be.deep.equal([312 {313 address,314 event: 'Transfer',315 args: {316 from: subToEth(alice.address),317 to: '0x0000000000000000000000000000000000000000',318 tokenId: tokenId.toString(),319 },320 },321 ]);322 });323196 itWeb3('Events emitted for approve()', async ({ web3 }) => {324 itWeb3('Events emitted for approve()', async ({ web3 }) => {197 const collection = await createCollectionExpectSuccess({325 const collection = await createCollectionExpectSuccess({tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth49 "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]