difftreelog
CORE-325 Fix metadata name and symbol
in: master
2 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth77#[solidity_interface(name = "ERC721Metadata")]77#[solidity_interface(name = "ERC721Metadata")]78impl<T: Config> NonfungibleHandle<T> {78impl<T: Config> NonfungibleHandle<T> {79 fn name(&self) -> Result<string> {79 fn name(&self) -> Result<string> {80 if let SchemaVersion::ImageURL = self.schema_version {81 Ok(decode_utf16(self.name.iter().copied())80 Ok(decode_utf16(self.name.iter().copied())82 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))81 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))83 .collect::<string>())82 .collect::<string>())84 } else {8385 Err(error_unsupported_shema_version())86 }87 }84 }85 88 fn symbol(&self) -> Result<string> {86 fn symbol(&self) -> Result<string> {89 if let SchemaVersion::ImageURL = self.schema_version {90 Ok(string::from_utf8_lossy(&self.token_prefix).into())87 Ok(string::from_utf8_lossy(&self.token_prefix).into())91 } else {92 Err(error_unsupported_shema_version())93 }94 }88 }958996 /// Returns token's const_metadata90 /// Returns token's const_metadatatests/src/eth/metadata.test.tsdiffbeforeafterboth72 const collectionId = await createCollectionExpectSuccess({72 const collectionId = await createCollectionExpectSuccess({73 mode: {type: 'NFT'},73 mode: {type: 'NFT'},74 shemaVersion: 'Unique',74 shemaVersion: 'Unique',75 name: 'some_name',76 tokenPrefix: 'some_prefix',75 });77 });76 const collection = await api.rpc.unique.collectionById(collectionId);78 const collection = await api.rpc.unique.collectionById(collectionId);77 expect(collection.isSome).to.be.true;79 expect(collection.isSome).to.be.true;86 const address = collectionIdToAddress(collectionId);88 const address = collectionIdToAddress(collectionId);87 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});89 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});889089 await expect(contract.methods.name().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');91 expect(await contract.methods.name().call()).to.be.eq('some_name');90 await expect(contract.methods.symbol().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');92 expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');919392 const receiver = createEthAccount(web3);94 const receiver = createEthAccount(web3);93 const nextTokenId = await contract.methods.nextTokenId().call();95 const nextTokenId = await contract.methods.nextTokenId().call();131 expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');133 expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');132134133 const receiver = createEthAccount(web3);135 const receiver = createEthAccount(web3);136 { // mintWithTokenURI134 const nextTokenId = await contract.methods.nextTokenId().call();137 const nextTokenId = await contract.methods.nextTokenId().call();135 expect(nextTokenId).to.be.equal('1');138 expect(nextTokenId).to.be.equal('1');136 const result = await contract.methods.mintWithTokenURI(139 const result = await contract.methods.mintWithTokenURI(153 ]);156 ]);154157 155 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');158 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');159 }160161 { // mintBulkWithTokenURI162 const nextTokenId = await contract.methods.nextTokenId().call();163 expect(nextTokenId).to.be.equal('2');164 const result = await contract.methods.mintBulkWithTokenURI(165 receiver,166 [167 [nextTokenId, 'Test URI 0'],168 [+nextTokenId + 1, 'Test URI 1'],169 [+nextTokenId + 2, 'Test URI 2'],170 ],171 ).send({from: caller});172 const events = normalizeEvents(result.events);173174 expect(events).to.be.deep.equal([175 {176 address,177 event: 'Transfer',178 args: {179 from: '0x0000000000000000000000000000000000000000',180 to: receiver,181 tokenId: nextTokenId,182 },183 },184 {185 address,186 event: 'Transfer',187 args: {188 from: '0x0000000000000000000000000000000000000000',189 to: receiver,190 tokenId: String(+nextTokenId + 1),191 },192 },193 {194 address,195 event: 'Transfer',196 args: {197 from: '0x0000000000000000000000000000000000000000',198 to: receiver,199 tokenId: String(+nextTokenId + 2),200 },201 },202 ]);203204 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');205 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');206 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');207 }156 });208 });157});209});158210