git.delta.rocks / unique-network / refs/commits / b7135593579f

difftreelog

chore remove URI ttp from clean collections

Grigoriy Simonov2022-10-13parent: #48f9593.patch.diff
in: master

4 files changed

modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
30};30};
31use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};31use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
33use sp_std::vec;
33use up_data_structs::{34use up_data_structs::{
34 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,35 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
35 CollectionMode, PropertyValue,36 CollectionMode, PropertyValue,
96 base_uri_value: PropertyValue,97 base_uri_value: PropertyValue,
97 add_properties: bool,98 add_properties: bool,
98) -> Result<CreateCollectionData<T::AccountId>> {99) -> Result<CreateCollectionData<T::AccountId>> {
99 let mut properties = up_data_structs::CollectionPropertiesVec::default();100 let token_property_permissions = if add_properties {
100 let mut token_property_permissions =101 vec![
101 up_data_structs::CollectionPropertiesPermissionsVec::default();
102
103 token_property_permissions
104 .try_push(up_data_structs::PropertyKeyPermission {102 up_data_structs::PropertyKeyPermission {
105 key: key::url(),103 key: key::url(),
106 permission: up_data_structs::PropertyPermission {104 permission: up_data_structs::PropertyPermission {
107 mutable: true,105 mutable: true,
108 collection_admin: true,106 collection_admin: true,
109 token_owner: false,107 token_owner: false,
110 },108 },
111 })109 },
110 up_data_structs::PropertyKeyPermission {
111 key: key::suffix(),
112 permission: up_data_structs::PropertyPermission {
113 mutable: true,
114 collection_admin: true,
115 token_owner: false,
116 },
117 },
118 ]
119 .try_into()
112 .map_err(|e| Error::Revert(format!("{:?}", e)))?;120 .map_err(|e| Error::Revert(format!("{:?}", e)))?
113121 } else {
122 up_data_structs::CollectionPropertiesPermissionsVec::default()
123 };
114 if add_properties {124 let properties = if add_properties {
115 token_property_permissions
116 .try_push(up_data_structs::PropertyKeyPermission {
117 key: key::suffix(),
118 permission: up_data_structs::PropertyPermission {
119 mutable: true,
120 collection_admin: true,
121 token_owner: false,
122 },
123 })
124 .map_err(|e| Error::Revert(format!("{:?}", e)))?;
125
126 properties125 let mut properties = vec![
127 .try_push(up_data_structs::Property {126 up_data_structs::Property {
128 key: key::schema_name(),127 key: key::schema_name(),
129 value: property_value::erc721(),128 value: property_value::erc721(),
130 })129 },
131 .map_err(|e| Error::Revert(format!("{:?}", e)))?;130 up_data_structs::Property {
132131 key: key::schema_version(),
132 value: property_value::schema_version(),
133 },
134 up_data_structs::Property {
135 key: key::erc721_metadata(),
136 value: property_value::erc721_metadata_supported(),
137 },
138 ];
139 if !base_uri_value.is_empty() {
133 properties140 properties.push(up_data_structs::Property {
134 .try_push(up_data_structs::Property {
135 key: key::schema_version(),141 key: key::base_uri(),
136 value: property_value::schema_version(),142 value: base_uri_value,
137 })143 })
138 .map_err(|e| Error::Revert(format!("{:?}", e)))?;144 }
139
140 properties145 properties
141 .try_push(up_data_structs::Property {146 .try_into()
142 key: key::erc721_metadata(),
143 value: property_value::erc721_metadata_supported(),
144 })
145 .map_err(|e| Error::Revert(format!("{:?}", e)))?;147 .map_err(|e| Error::Revert(format!("{:?}", e)))?
146
147 if !base_uri_value.is_empty() {
148 properties
149 .try_push(up_data_structs::Property {
150 key: key::base_uri(),
151 value: base_uri_value,
152 })
153 .map_err(|e| Error::Revert(format!("{:?}", e)))?;
154 }
155 }148 } else {
149 up_data_structs::CollectionPropertiesVec::default()
150 };
156151
157 let data = CreateCollectionData {152 let data = CreateCollectionData {
158 name,153 name,
deletedtests/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 {}
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
--- 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.
modifiedtests/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.