difftreelog
test mintBulk/metadata api
in: master
2 files changed
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth4//4//556import 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');113114 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);118119 const address = collectionIdToAddress(collection);120 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});121122 {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);134135 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 ]);164165 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 });109171110 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 });329330 itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => {331 const collection = await createCollectionExpectSuccess({332 mode: { type: 'NFT' },333 });334 const alice = privateKey('//Alice');335336 const owner = await createEthAccountWithBalance(api, web3);337338 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });339 await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]);340341 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 });346347 itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => {348 const collection = await createCollectionExpectSuccess({349 mode: { type: 'NFT' },350 });351 const alice = privateKey('//Alice');352353 const owner = await createEthAccountWithBalance(api, web3);354355 const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });356357 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});268365269describe('NFT: Fees', () => {366describe('NFT: Fees', () => {tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth50 "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 {