difftreelog
chore remove URI ttp from clean collections
in: master
4 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- 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<CreateCollectionData<T::AccountId>> {
- 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,
tests/src/eth/api/UniqueRFT.soldiffbeforeafterboth--- 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 {}
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth50 expect(data.raw.tokenPrefix).to.be.eq(prefix);50 expect(data.raw.tokenPrefix).to.be.eq(prefix);51 expect(data.raw.mode).to.be.eq('NFT');51 expect(data.raw.mode).to.be.eq('NFT');5253 const options = await collection.getOptions();5455 expect(options.tokenPropertyPermissions).to.be.empty;52 });56 });5758 itEth('Create collection with properties', async ({helper}) => {59 const owner = await helper.eth.createAccountWithBalance(donor);6061 const name = 'CollectionEVM';62 const description = 'Some description';63 const prefix = 'token prefix';64 const baseUri = 'BaseURI';6566 // todo:playgrounds this might fail when in async environment.67 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;68 const {collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);69 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;7071 const collection = helper.nft.getCollectionObject(collectionId);72 const data = (await collection.getData())!;73 74 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);75 expect(collectionId).to.be.eq(collectionCountAfter);76 expect(data.name).to.be.eq(name);77 expect(data.description).to.be.eq(description);78 expect(data.raw.tokenPrefix).to.be.eq(prefix);79 expect(data.raw.mode).to.be.eq('NFT');8081 const options = await collection.getOptions();82 expect(options.tokenPropertyPermissions).to.be.deep.equal([83 {84 key: 'URI',85 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},86 },87 {88 key: 'URISuffix',89 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},90 },91 ]);92 });539354 // todo:playgrounds this test will fail when in async environment.94 // todo:playgrounds this test will fail when in async environment.55 itEth('Check collection address exist', async ({helper}) => {95 itEth('Check collection address exist', async ({helper}) => {tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- 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.