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
--- 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,
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
42 const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix);42 const {collectionId} = await helper.eth.createRFTCollection(owner, name, description, prefix);
43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
44 44
45 const collection = helper.rft.getCollectionObject(collectionId);
45 const data = (await helper.rft.getData(collectionId))!;46 const data = (await collection.getData())!;
4647
47 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);48 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
48 expect(collectionId).to.be.eq(collectionCountAfter);49 expect(collectionId).to.be.eq(collectionCountAfter);
51 expect(data.raw.tokenPrefix).to.be.eq(prefix);52 expect(data.raw.tokenPrefix).to.be.eq(prefix);
52 expect(data.raw.mode).to.be.eq('ReFungible');53 expect(data.raw.mode).to.be.eq('ReFungible');
54
55 const options = await collection.getOptions();
56
57 expect(options.tokenPropertyPermissions).to.be.empty;
53 });58 });
59
60
61
62 itEth('Create collection with properties', async ({helper}) => {
63 const owner = await helper.eth.createAccountWithBalance(donor);
64
65 const name = 'CollectionEVM';
66 const description = 'Some description';
67 const prefix = 'token prefix';
68 const baseUri = 'BaseURI';
69
70 // todo:playgrounds this might fail when in async environment.
71 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
72 const {collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, name, description, prefix, baseUri);
73 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
74
75 const collection = helper.rft.getCollectionObject(collectionId);
76 const data = (await collection.getData())!;
77
78 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
79 expect(collectionId).to.be.eq(collectionCountAfter);
80 expect(data.name).to.be.eq(name);
81 expect(data.description).to.be.eq(description);
82 expect(data.raw.tokenPrefix).to.be.eq(prefix);
83 expect(data.raw.mode).to.be.eq('ReFungible');
84
85 const options = await collection.getOptions();
86 expect(options.tokenPropertyPermissions).to.be.deep.equal([
87 {
88 key: 'URI',
89 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},
90 },
91 {
92 key: 'URISuffix',
93 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},
94 },
95 ]);
96 });
5497
55 // todo:playgrounds this test will fail when in async environment.98 // todo:playgrounds this test will fail when in async environment.
56 itEth('Check collection address exist', async ({helper}) => {99 itEth('Check collection address exist', async ({helper}) => {