difftreelog
chore add check in `supports_metadata`
in: master
9 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -225,10 +225,6 @@
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
fn token_uri(&self, token_id: uint256) -> Result<string> {
- if !self.supports_metadata() {
- return Ok("".into());
- }
-
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -714,13 +710,17 @@
impl<T: Config> NonfungibleHandle<T> {
pub fn supports_metadata(&self) -> bool {
- if let Some(erc721_metadata) =
+ let has_metadata_support_enabled = if let Some(erc721_metadata) =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
{
*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
} else {
false
- }
+ };
+
+ let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
+
+ has_metadata_support_enabled && has_url_property_permissions
}
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -108,7 +108,6 @@
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
- erc::static_property::{key, value},
eth::collection_id_to_address,
};
use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -218,10 +218,6 @@
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
fn token_uri(&self, token_id: uint256) -> Result<string> {
- if !self.supports_metadata() {
- return Ok("".into());
- }
-
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -770,13 +766,17 @@
impl<T: Config> RefungibleHandle<T> {
pub fn supports_metadata(&self) -> bool {
- if let Some(erc721_metadata) =
+ let has_metadata_support_enabled = if let Some(erc721_metadata) =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::erc721_metadata())
{
*erc721_metadata.into_inner() == *value::ERC721_METADATA_SUPPORTED
} else {
false
- }
+ };
+
+ let has_url_property_permissions = get_token_permission::<T>(self.id, &key::url()).is_ok();
+
+ has_metadata_support_enabled && has_url_property_permissions
}
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -101,10 +101,7 @@
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_evm_coder_substrate::WithRecorder;
use pallet_common::{
- CommonCollectionOperations,
- erc::static_property::{key, value},
- Error as CommonError,
- eth::collection_id_to_address,
+ CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,
Event as CommonEvent, Pallet as PalletCommon,
};
use pallet_structure::Pallet as PalletStructure;
tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -80,7 +80,23 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
const donor = privateKey('//Alice');
const [alice] = await helper.arrange.createAccounts([10n], donor);
- ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties: [{key: 'ERC721Metadata', value: '1'}]}));
+ ({collectionId: collection} = await helper.nft.mintCollection(
+ alice,
+ {
+ name: 'test',
+ description: 'test',
+ tokenPrefix: 'test',
+ properties: [{key: 'ERC721Metadata', value: '1'}],
+ tokenPropertyPermissions: [{
+ key: 'URI',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ tokenOwner: false,
+ },
+ }],
+ },
+ ));
minter = helper.eth.createAccount();
});
});
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -67,7 +67,15 @@
itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const tokenPropertyPermissions = [{
+ key: 'URI',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ tokenOwner: false,
+ },
+ }];
+ const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});
await collection.addAdmin(donor, {Ethereum: caller});
const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
@@ -83,7 +91,15 @@
itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const tokenPropertyPermissions = [{
+ key: 'URI',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ tokenOwner: false,
+ },
+ }];
+ const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});
await collection.addAdmin(donor, {Ethereum: caller});
tests/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.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -377,7 +377,23 @@
itEth('Returns collection name', async ({helper}) => {
const caller = helper.eth.createAccount();
- const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11', properties: [{key: 'ERC721Metadata', value: '1'}]});
+ const tokenPropertyPermissions = [{
+ key: 'URI',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ tokenOwner: false,
+ },
+ }];
+ const collection = await helper.rft.mintCollection(
+ alice,
+ {
+ name: 'Leviathan',
+ tokenPrefix: '11',
+ properties: [{key: 'ERC721Metadata', value: '1'}],
+ tokenPropertyPermissions,
+ },
+ );
const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);
const name = await contract.methods.name().call();
@@ -386,7 +402,24 @@
itEth('Returns symbol name', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12', properties: [{key: 'ERC721Metadata', value: '1'}]});
+ const tokenPropertyPermissions = [{
+ key: 'URI',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ tokenOwner: false,
+ },
+ }];
+ const {collectionId} = await helper.rft.mintCollection(
+ alice,
+ {
+ name: 'Leviathan',
+ tokenPrefix: '12',
+ properties: [{key: 'ERC721Metadata', value: '1'}],
+ tokenPropertyPermissions,
+ },
+ );
+
const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);
const symbol = await contract.methods.symbol().call();
expect(symbol).to.equal('12');
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -213,7 +213,7 @@
async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
+
const result = await collectionHelper.methods.createERC721MetadataCompatibleRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);