difftreelog
chore add check in `supports_metadata`
in: master
9 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth225 /// @return token's const_metadata225 /// @return token's const_metadata226 #[solidity(rename_selector = "tokenURI")]226 #[solidity(rename_selector = "tokenURI")]227 fn token_uri(&self, token_id: uint256) -> Result<string> {227 fn token_uri(&self, token_id: uint256) -> Result<string> {228 if !self.supports_metadata() {229 return Ok("".into());230 }231232 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;228 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;233229714710715impl<T: Config> NonfungibleHandle<T> {711impl<T: Config> NonfungibleHandle<T> {716 pub fn supports_metadata(&self) -> bool {712 pub fn supports_metadata(&self) -> bool {717 if let Some(erc721_metadata) =713 let has_metadata_support_enabled = if let Some(erc721_metadata) =718 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())714 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())719 {715 {720 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED716 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED721 } else {717 } else {722 false718 false723 }719 };720721 let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();722723 has_metadata_support_enabled && has_url_property_permissions724 }724 }725}725}726726pallets/nonfungible/src/lib.rsdiffbeforeafterboth108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};109use pallet_common::{109use pallet_common::{110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,111 erc::static_property::{key, value},112 eth::collection_id_to_address,111 eth::collection_id_to_address,113};112};114use pallet_structure::{Pallet as PalletStructure, Error as StructureError};113use pallet_structure::{Pallet as PalletStructure, Error as StructureError};pallets/refungible/src/erc.rsdiffbeforeafterboth218 /// @return token's const_metadata218 /// @return token's const_metadata219 #[solidity(rename_selector = "tokenURI")]219 #[solidity(rename_selector = "tokenURI")]220 fn token_uri(&self, token_id: uint256) -> Result<string> {220 fn token_uri(&self, token_id: uint256) -> Result<string> {221 if !self.supports_metadata() {222 return Ok("".into());223 }224225 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;226222770766771impl<T: Config> RefungibleHandle<T> {767impl<T: Config> RefungibleHandle<T> {772 pub fn supports_metadata(&self) -> bool {768 pub fn supports_metadata(&self) -> bool {773 if let Some(erc721_metadata) =769 let has_metadata_support_enabled = if let Some(erc721_metadata) =774 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())770 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())775 {771 {776 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED772 *erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED777 } else {773 } else {778 false774 false779 }775 };776777 let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();778779 has_metadata_support_enabled && has_url_property_permissions780 }780 }781}781}782782pallets/refungible/src/lib.rsdiffbeforeafterboth102use pallet_evm_coder_substrate::WithRecorder;102use pallet_evm_coder_substrate::WithRecorder;103use pallet_common::{103use pallet_common::{104 CommonCollectionOperations,104 CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,105 erc::static_property::{key, value},106 Error as CommonError,107 eth::collection_id_to_address,108 Event as CommonEvent, Pallet as PalletCommon,105 Event as CommonEvent, Pallet as PalletCommon,tests/src/eth/base.test.tsdiffbeforeafterboth86 name: 'test',87 description: 'test',88 tokenPrefix: 'test',89 properties: [{key: 'ERC721Metadata', value: '1'}],90 tokenPropertyPermissions: [{91 key: 'URI',92 permission: {93 mutable: true,94 collectionAdmin: true,95 tokenOwner: false,96 },97 }],98 },99 ));84 minter = helper.eth.createAccount();100 minter = helper.eth.createAccount();85 });101 });tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth676768 itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {68 itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {69 const caller = await helper.eth.createAccountWithBalance(donor);69 const caller = await helper.eth.createAccountWithBalance(donor);70 const tokenPropertyPermissions = [{71 key: 'URI',72 permission: {73 mutable: true,74 collectionAdmin: true,75 tokenOwner: false,76 },77 }];70 const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});78 const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});717972 await collection.addAdmin(donor, {Ethereum: caller});80 await collection.addAdmin(donor, {Ethereum: caller});73 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);81 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);839184 itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {92 itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {85 const caller = await helper.eth.createAccountWithBalance(donor);93 const caller = await helper.eth.createAccountWithBalance(donor);94 const tokenPropertyPermissions = [{95 key: 'URI',96 permission: {97 mutable: true,98 collectionAdmin: true,99 tokenOwner: false,100 },101 }];86 const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});102 const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});8710388 await collection.addAdmin(donor, {Ethereum: caller});104 await collection.addAdmin(donor, {Ethereum: caller});89105tests/src/eth/nonFungible.test.tsdiffbeforeafterboth501501502 itEth('Returns collection name', async ({helper}) => {502 itEth('Returns collection name', async ({helper}) => {503 const caller = await helper.eth.createAccountWithBalance(donor);503 const caller = await helper.eth.createAccountWithBalance(donor);504 const tokenPropertyPermissions = [{505 key: 'URI',506 permission: {507 mutable: true,508 collectionAdmin: true,509 tokenOwner: false,510 },511 }];504 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});512 const collection = await helper.nft.mintCollection(513 alice,514 {515 name: 'oh River',516 tokenPrefix: 'CHANGE',517 properties: [{key: 'ERC721Metadata', value: '1'}],518 tokenPropertyPermissions,519 },520 );505521506 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);522 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);510526511 itEth('Returns symbol name', async ({helper}) => {527 itEth('Returns symbol name', async ({helper}) => {512 const caller = await helper.eth.createAccountWithBalance(donor);528 const caller = await helper.eth.createAccountWithBalance(donor);529 const tokenPropertyPermissions = [{530 key: 'URI',531 permission: {532 mutable: true,533 collectionAdmin: true,534 tokenOwner: false,535 },536 }];513 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE', properties: [{key: 'ERC721Metadata', value: '1'}]});537 const collection = await helper.nft.mintCollection(538 alice,539 {540 name: 'oh River',541 tokenPrefix: 'CHANGE',542 properties: [{key: 'ERC721Metadata', value: '1'}],543 tokenPropertyPermissions,544 },545 );514546515 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);547 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);tests/src/eth/reFungible.test.tsdiffbeforeafterboth377377378 itEth('Returns collection name', async ({helper}) => {378 itEth('Returns collection name', async ({helper}) => {379 const caller = helper.eth.createAccount();379 const caller = helper.eth.createAccount();380 const tokenPropertyPermissions = [{381 key: 'URI',382 permission: {383 mutable: true,384 collectionAdmin: true,385 tokenOwner: false,386 },387 }];380 const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11', properties: [{key: 'ERC721Metadata', value: '1'}]});388 const collection = await helper.rft.mintCollection(381 389 alice,390 {391 name: 'Leviathan',392 tokenPrefix: '11',393 properties: [{key: 'ERC721Metadata', value: '1'}],394 tokenPropertyPermissions,395 },396 );397 382 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);398 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);386402387 itEth('Returns symbol name', async ({helper}) => {403 itEth('Returns symbol name', async ({helper}) => {388 const caller = await helper.eth.createAccountWithBalance(donor);404 const caller = await helper.eth.createAccountWithBalance(donor);405 const tokenPropertyPermissions = [{406 key: 'URI',407 permission: {408 mutable: true,409 collectionAdmin: true,410 tokenOwner: false,411 },412 }];389 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12', properties: [{key: 'ERC721Metadata', value: '1'}]});413 const {collectionId} = await helper.rft.mintCollection(414 alice,415 {416 name: 'Leviathan',417 tokenPrefix: '12',418 properties: [{key: 'ERC721Metadata', value: '1'}],419 tokenPropertyPermissions,420 },421 );422390 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);423 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterbothno syntactic changes