difftreelog
tests: add tests for tokenURI
in: master
1 file changed
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth72 });72 });73});73});7475describe.only('Check ERC721 token URI', () => {76 itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {77 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);78 const helper = evmCollectionHelpers(web3, owner);79 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();80 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);81 const receiver = createEthAccount(web3);82 const contract = evmCollection(web3, owner, collectionIdAddress);83 84 const nextTokenId = await contract.methods.nextTokenId().call();85 expect(nextTokenId).to.be.equal('1');86 result = await contract.methods.mint(87 receiver,88 nextTokenId,89 ).send();9091 const events = normalizeEvents(result.events);92 const address = collectionIdToAddress(collectionId);9394 expect(events).to.be.deep.equal([95 {96 address,97 event: 'Transfer',98 args: {99 from: '0x0000000000000000000000000000000000000000',100 to: receiver,101 tokenId: nextTokenId,102 },103 },104 ]);105106 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');107 });108109 itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {110 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);111 const helper = evmCollectionHelpers(web3, owner);112 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();113 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);114 const receiver = createEthAccount(web3);115 const contract = evmCollection(web3, owner, collectionIdAddress);116 117 const nextTokenId = await contract.methods.nextTokenId().call();118 expect(nextTokenId).to.be.equal('1');119 result = await contract.methods.mint(120 receiver,121 nextTokenId,122 ).send();123 124 // Set URL125 await contract.methods.setProperty(nextTokenId, 'u', Buffer.from('Token URI')).send();126 127 const events = normalizeEvents(result.events);128 const address = collectionIdToAddress(collectionId);129130 expect(events).to.be.deep.equal([131 {132 address,133 event: 'Transfer',134 args: {135 from: '0x0000000000000000000000000000000000000000',136 to: receiver,137 tokenId: nextTokenId,138 },139 },140 ]);141142 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');143 });144145 itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {146 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);147 const helper = evmCollectionHelpers(web3, owner);148 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();149 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);150 const receiver = createEthAccount(web3);151 const contract = evmCollection(web3, owner, collectionIdAddress);152 153 const nextTokenId = await contract.methods.nextTokenId().call();154 expect(nextTokenId).to.be.equal('1');155 result = await contract.methods.mint(156 receiver,157 nextTokenId,158 ).send();159 160 const events = normalizeEvents(result.events);161 const address = collectionIdToAddress(collectionId);162163 expect(events).to.be.deep.equal([164 {165 address,166 event: 'Transfer',167 args: {168 from: '0x0000000000000000000000000000000000000000',169 to: receiver,170 tokenId: nextTokenId,171 },172 },173 ]);174175 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);176 });177178 itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {179 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);180 const helper = evmCollectionHelpers(web3, owner);181 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();182 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);183 const receiver = createEthAccount(web3);184 const contract = evmCollection(web3, owner, collectionIdAddress);185 186 const nextTokenId = await contract.methods.nextTokenId().call();187 expect(nextTokenId).to.be.equal('1');188 result = await contract.methods.mint(189 receiver,190 nextTokenId,191 ).send();192 193 // Set suffix194 const suffix = '/some/suffix';195 await contract.methods.setProperty(nextTokenId, 's', Buffer.from(suffix)).send();196197 const events = normalizeEvents(result.events);198 const address = collectionIdToAddress(collectionId);199200 expect(events).to.be.deep.equal([201 {202 address,203 event: 'Transfer',204 args: {205 from: '0x0000000000000000000000000000000000000000',206 to: receiver,207 tokenId: nextTokenId,208 },209 },210 ]);211212 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);213 });214});7421575describe('NFT: Plain calls', () => {216describe('NFT: Plain calls', () => {76 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {217 itWeb3.only('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {77 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);218 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);78 const helper = evmCollectionHelpers(web3, owner);219 const helper = evmCollectionHelpers(web3, owner);79 let result = await helper.methods.createNonfungibleCollection('Mint collection', '6', '6').send();220 let result = await helper.methods.createNonfungibleCollection('Mint collection', '6', '6').send();