From b7135593579f3ab90e988c80d58e4a840f5b0bfc Mon Sep 17 00:00:00 2001 From: Grigoriy Simonov Date: Thu, 13 Oct 2022 09:05:17 +0000 Subject: [PATCH] chore: remove URI ttp from clean collections --- --- a/pallets/unique/src/eth/mod.rs +++ b/pallets/unique/src/eth/mod.rs @@ -30,6 +30,7 @@ }; use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder}; use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult}; +use sp_std::vec; use up_data_structs::{ CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData, CollectionMode, PropertyValue, @@ -96,63 +97,57 @@ base_uri_value: PropertyValue, add_properties: bool, ) -> Result> { - let mut properties = up_data_structs::CollectionPropertiesVec::default(); - let mut token_property_permissions = - up_data_structs::CollectionPropertiesPermissionsVec::default(); - - token_property_permissions - .try_push(up_data_structs::PropertyKeyPermission { - key: key::url(), - permission: up_data_structs::PropertyPermission { - mutable: true, - collection_admin: true, - token_owner: false, + let token_property_permissions = if add_properties { + vec![ + up_data_structs::PropertyKeyPermission { + key: key::url(), + permission: up_data_structs::PropertyPermission { + mutable: true, + collection_admin: true, + token_owner: false, + }, }, - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; - - if add_properties { - token_property_permissions - .try_push(up_data_structs::PropertyKeyPermission { + up_data_structs::PropertyKeyPermission { key: key::suffix(), permission: up_data_structs::PropertyPermission { mutable: true, collection_admin: true, token_owner: false, }, - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; - - properties - .try_push(up_data_structs::Property { + }, + ] + .try_into() + .map_err(|e| Error::Revert(format!("{:?}", e)))? + } else { + up_data_structs::CollectionPropertiesPermissionsVec::default() + }; + let properties = if add_properties { + let mut properties = vec![ + up_data_structs::Property { key: key::schema_name(), value: property_value::erc721(), - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; - - properties - .try_push(up_data_structs::Property { + }, + up_data_structs::Property { key: key::schema_version(), value: property_value::schema_version(), - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; - - properties - .try_push(up_data_structs::Property { + }, + up_data_structs::Property { key: key::erc721_metadata(), value: property_value::erc721_metadata_supported(), - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; - + }, + ]; if !base_uri_value.is_empty() { - properties - .try_push(up_data_structs::Property { - key: key::base_uri(), - value: base_uri_value, - }) - .map_err(|e| Error::Revert(format!("{:?}", e)))?; + properties.push(up_data_structs::Property { + key: key::base_uri(), + value: base_uri_value, + }) } - } + properties + .try_into() + .map_err(|e| Error::Revert(format!("{:?}", e)))? + } else { + up_data_structs::CollectionPropertiesVec::default() + }; let data = CreateCollectionData { name, --- a/tests/src/eth/api/UniqueRFT.sol +++ /dev/null @@ -1,163 +0,0 @@ -// SPDX-License-Identifier: OTHER -// This code is automatically generated - -pragma solidity >=0.8.0 <0.9.0; - -// Common stubs holder -interface Dummy { - -} - -interface ERC165 is Dummy { - function supportsInterface(bytes4 interfaceID) external view returns (bool); -} - -// Selector: 7d9262e6 -interface Collection is Dummy, ERC165 { - // Set collection property. - // - // @param key Property key. - // @param value Propery value. - // - // Selector: setCollectionProperty(string,bytes) 2f073f66 - function setCollectionProperty(string memory key, bytes memory value) - external; - - // Delete collection property. - // - // @param key Property key. - // - // Selector: deleteCollectionProperty(string) 7b7debce - function deleteCollectionProperty(string memory key) external; - - // Get collection property. - // - // @dev Throws error if key not found. - // - // @param key Property key. - // @return bytes The property corresponding to the key. - // - // Selector: collectionProperty(string) cf24fd6d - function collectionProperty(string memory key) - external - view - returns (bytes memory); - - // Set the sponsor of the collection. - // - // @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor. - // - // @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract. - // - // Selector: setCollectionSponsor(address) 7623402e - function setCollectionSponsor(address sponsor) external; - - // Collection sponsorship confirmation. - // - // @dev After setting the sponsor for the collection, it must be confirmed with this function. - // - // Selector: confirmCollectionSponsorship() 3c50e97a - function confirmCollectionSponsorship() external; - - // Set limits for the collection. - // @dev Throws error if limit not found. - // @param limit Name of the limit. Valid names: - // "accountTokenOwnershipLimit", - // "sponsoredDataSize", - // "sponsoredDataRateLimit", - // "tokenLimit", - // "sponsorTransferTimeout", - // "sponsorApproveTimeout" - // @param value Value of the limit. - // - // Selector: setCollectionLimit(string,uint32) 6a3841db - function setCollectionLimit(string memory limit, uint32 value) external; - - // Set limits for the collection. - // @dev Throws error if limit not found. - // @param limit Name of the limit. Valid names: - // "ownerCanTransfer", - // "ownerCanDestroy", - // "transfersEnabled" - // @param value Value of the limit. - // - // Selector: setCollectionLimit(string,bool) 993b7fba - function setCollectionLimit(string memory limit, bool value) external; - - // Get contract address. - // - // Selector: contractAddress() f6b4dfb4 - function contractAddress() external view returns (address); - - // Add collection admin by substrate address. - // @param new_admin Substrate administrator address. - // - // Selector: addCollectionAdminSubstrate(uint256) 5730062b - function addCollectionAdminSubstrate(uint256 newAdmin) external; - - // Remove collection admin by substrate address. - // @param admin Substrate administrator address. - // - // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9 - function removeCollectionAdminSubstrate(uint256 admin) external; - - // Add collection admin. - // @param new_admin Address of the added administrator. - // - // Selector: addCollectionAdmin(address) 92e462c7 - function addCollectionAdmin(address newAdmin) external; - - // Remove collection admin. - // - // @param new_admin Address of the removed administrator. - // - // Selector: removeCollectionAdmin(address) fafd7b42 - function removeCollectionAdmin(address admin) external; - - // Toggle accessibility of collection nesting. - // - // @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled' - // - // Selector: setCollectionNesting(bool) 112d4586 - function setCollectionNesting(bool enable) external; - - // Toggle accessibility of collection nesting. - // - // @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled' - // @param collections Addresses of collections that will be available for nesting. - // - // Selector: setCollectionNesting(bool,address[]) 64872396 - function setCollectionNesting(bool enable, address[] memory collections) - external; - - // Set the collection access method. - // @param mode Access mode - // 0 for Normal - // 1 for AllowList - // - // Selector: setCollectionAccess(uint8) 41835d4c - function setCollectionAccess(uint8 mode) external; - - // Add the user to the allowed list. - // - // @param user Address of a trusted user. - // - // Selector: addToCollectionAllowList(address) 67844fe6 - function addToCollectionAllowList(address user) external; - - // Remove the user from the allowed list. - // - // @param user Address of a removed user. - // - // Selector: removeFromCollectionAllowList(address) 85c51acb - function removeFromCollectionAllowList(address user) external; - - // Switch permission for minting. - // - // @param mode Enable if "true". - // - // Selector: setCollectionMintMode(bool) 00018e84 - function setCollectionMintMode(bool mode) external; -} - -interface UniqueRFT is Dummy, ERC165, Collection {} --- a/tests/src/eth/createNFTCollection.test.ts +++ b/tests/src/eth/createNFTCollection.test.ts @@ -49,6 +49,46 @@ expect(data.description).to.be.eq(description); expect(data.raw.tokenPrefix).to.be.eq(prefix); expect(data.raw.mode).to.be.eq('NFT'); + + const options = await collection.getOptions(); + + expect(options.tokenPropertyPermissions).to.be.empty; + }); + + itEth('Create collection with properties', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + + const name = 'CollectionEVM'; + const description = 'Some description'; + const prefix = 'token prefix'; + const baseUri = 'BaseURI'; + + // todo:playgrounds this might fail when in async environment. + const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created; + const {collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri); + const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created; + + const collection = helper.nft.getCollectionObject(collectionId); + const data = (await collection.getData())!; + + expect(collectionCountAfter - collectionCountBefore).to.be.eq(1); + expect(collectionId).to.be.eq(collectionCountAfter); + expect(data.name).to.be.eq(name); + expect(data.description).to.be.eq(description); + expect(data.raw.tokenPrefix).to.be.eq(prefix); + expect(data.raw.mode).to.be.eq('NFT'); + + const options = await collection.getOptions(); + expect(options.tokenPropertyPermissions).to.be.deep.equal([ + { + key: 'URI', + permission: {mutable: true, collectionAdmin: true, tokenOwner: false}, + }, + { + key: 'URISuffix', + permission: {mutable: true, collectionAdmin: true, tokenOwner: false}, + }, + ]); }); // todo:playgrounds this test will fail when in async environment. --- a/tests/src/eth/createRFTCollection.test.ts +++ b/tests/src/eth/createRFTCollection.test.ts @@ -42,7 +42,8 @@ const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix); const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created; - const data = (await helper.rft.getData(collectionId))!; + const collection = helper.rft.getCollectionObject(collectionId); + const data = (await collection.getData())!; expect(collectionCountAfter - collectionCountBefore).to.be.eq(1); expect(collectionId).to.be.eq(collectionCountAfter); @@ -50,6 +51,48 @@ expect(data.description).to.be.eq(description); expect(data.raw.tokenPrefix).to.be.eq(prefix); expect(data.raw.mode).to.be.eq('ReFungible'); + + const options = await collection.getOptions(); + + expect(options.tokenPropertyPermissions).to.be.empty; + }); + + + + itEth('Create collection with properties', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + + const name = 'CollectionEVM'; + const description = 'Some description'; + const prefix = 'token prefix'; + const baseUri = 'BaseURI'; + + // todo:playgrounds this might fail when in async environment. + const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created; + const {collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, name, description, prefix, baseUri); + const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created; + + const collection = helper.rft.getCollectionObject(collectionId); + const data = (await collection.getData())!; + + expect(collectionCountAfter - collectionCountBefore).to.be.eq(1); + expect(collectionId).to.be.eq(collectionCountAfter); + expect(data.name).to.be.eq(name); + expect(data.description).to.be.eq(description); + expect(data.raw.tokenPrefix).to.be.eq(prefix); + expect(data.raw.mode).to.be.eq('ReFungible'); + + const options = await collection.getOptions(); + expect(options.tokenPropertyPermissions).to.be.deep.equal([ + { + key: 'URI', + permission: {mutable: true, collectionAdmin: true, tokenOwner: false}, + }, + { + key: 'URISuffix', + permission: {mutable: true, collectionAdmin: true, tokenOwner: false}, + }, + ]); }); // todo:playgrounds this test will fail when in async environment. -- gitstuff