git.delta.rocks / unique-network / refs/commits / 4375a2d3ddf0

difftreelog

CORE-412 Add create_refungible_collection method

Trubnikov Sergey2022-06-14parent: #e5c8c50.patch.diff
in: master

5 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6649,6 +6649,7 @@
  "pallet-evm",
  "pallet-evm-coder-substrate",
  "pallet-nonfungible",
+ "pallet-refungible",
  "parity-scale-codec 3.1.5",
  "scale-info",
  "serde",
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -103,3 +103,4 @@
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
 pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }
+pallet-refungible = { default-features = false, path = '../../pallets/refungible' }
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
210 Ok(address)210 Ok(address)
211 }211 }
212
213 #[weight(<SelfWeightOf<T>>::create_collection())]
214 fn create_refungible_collection(
215 &self,
216 caller: caller,
217 name: string,
218 description: string,
219 token_prefix: string,
220 ) -> Result<address> {
221 let (caller, name, description, token_prefix) =
222 convert_data::<T>(caller, name, description, token_prefix)?;
223 let data = make_data::<T>(name, description, token_prefix)?;
224 let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)
225 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
226
227 let address = pallet_common::eth::collection_id_to_address(collection_id);
228 Ok(address)
229 }
212230
213 /// Check if a collection exists231 /// Check if a collection exists
214 /// @param collection_address Address of the collection in question232 /// @param collection_address Address of the collection in question
225243
226/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]244/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
227pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);245pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);
228impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {246impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>
247 for CollectionHelpersOnMethodCall<T>
248{
229 fn is_reserved(contract: &sp_core::H160) -> bool {249 fn is_reserved(contract: &sp_core::H160) -> bool {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -298,9 +298,9 @@
 	pub mode: CollectionMode,
 	#[version(..2)]
 	pub access: AccessMode,
-	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
+	pub name: CollectionName,
+	pub description: CollectionDescription,
+	pub token_prefix: CollectionTokenPrefix,
 
 	#[version(..2)]
 	pub mint_mode: bool,
@@ -354,9 +354,9 @@
 	#[derivative(Default(value = "CollectionMode::NFT"))]
 	pub mode: CollectionMode,
 	pub access: Option<AccessMode>,
-	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
+	pub name: CollectionName,
+	pub description: CollectionDescription,
+	pub token_prefix: CollectionTokenPrefix,
 	pub pending_sponsor: Option<AccountId>,
 	pub limits: Option<CollectionLimits>,
 	pub permissions: Option<CollectionPermissions>,
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -27,46 +27,46 @@
   getCollectionAddressFromResult,
 } from './util/helpers';
 
-describe('Create collection from EVM', () => {
-  // itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {
-  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-  //   const collectionHelper = evmCollectionHelpers(web3, owner);
-  //   const collectionName = 'CollectionEVM';
-  //   const description = 'Some description';
-  //   const tokenPrefix = 'token prefix';
+describe.only('Create collection from EVM', () => {
+  itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const collectionHelper = evmCollectionHelpers(web3, owner);
+    const collectionName = 'CollectionEVM';
+    const description = 'Some description';
+    const tokenPrefix = 'token prefix';
   
-  //   const collectionCountBefore = await getCreatedCollectionCount(api);
-  //   const result = await collectionHelper.methods
-  //     .createNonfungibleCollection(collectionName, description, tokenPrefix)
-  //     .send();
-  //   const collectionCountAfter = await getCreatedCollectionCount(api);
+    const collectionCountBefore = await getCreatedCollectionCount(api);
+    const result = await collectionHelper.methods
+      .createNonfungibleCollection(collectionName, description, tokenPrefix)
+      .send();
+    const collectionCountAfter = await getCreatedCollectionCount(api);
   
-  //   const {collectionId, collection} = await getCollectionAddressFromResult(api, result);
-  //   expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
-  //   expect(collectionId).to.be.eq(collectionCountAfter);
-  //   expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
-  //   expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
-  //   expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
-  // });
+    const {collectionId, collection} = await getCollectionAddressFromResult(api, result);
+    expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
+    expect(collectionId).to.be.eq(collectionCountAfter);
+    expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);
+    expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);
+    expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);
+  });
 
-  // itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {
-  //   const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-  //   const collectionHelpers = evmCollectionHelpers(web3, owner);
+  itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const collectionHelpers = evmCollectionHelpers(web3, owner);
   
-  //   const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
-  //   const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
-  //   expect(await collectionHelpers.methods
-  //     .isCollectionExist(expectedCollectionAddress)
-  //     .call()).to.be.false;
+    const expectedCollectionId = await getCreatedCollectionCount(api) + 1;
+    const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);
+    expect(await collectionHelpers.methods
+      .isCollectionExist(expectedCollectionAddress)
+      .call()).to.be.false;
 
-  //   await collectionHelpers.methods
-  //     .createNonfungibleCollection('A', 'A', 'A')
-  //     .send();
+    await collectionHelpers.methods
+      .createNonfungibleCollection('A', 'A', 'A')
+      .send();
     
-  //   expect(await collectionHelpers.methods
-  //     .isCollectionExist(expectedCollectionAddress)
-  //     .call()).to.be.true;
-  // });
+    expect(await collectionHelpers.methods
+      .isCollectionExist(expectedCollectionAddress)
+      .call()).to.be.true;
+  });
   
   itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);