difftreelog
CORE-412 Add create_refungible_collection method
in: master
5 files changed
Cargo.lockdiffbeforeafterboth6649 "pallet-evm",6649 "pallet-evm",6650 "pallet-evm-coder-substrate",6650 "pallet-evm-coder-substrate",6651 "pallet-nonfungible",6651 "pallet-nonfungible",6652 "pallet-refungible",6652 "parity-scale-codec 3.1.5",6653 "parity-scale-codec 3.1.5",6653 "scale-info",6654 "scale-info",6654 "serde",6655 "serde",pallets/unique/Cargo.tomldiffbeforeafterboth103evm-coder = { default-features = false, path = '../../crates/evm-coder' }103evm-coder = { default-features = false, path = '../../crates/evm-coder' }104pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }104pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }105pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }105pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }106pallet-refungible = { default-features = false, path = '../../pallets/refungible' }106107pallets/unique/src/eth/mod.rsdiffbeforeafterboth210 Ok(address)210 Ok(address)211 }211 }212213 #[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>)?;226227 let address = pallet_common::eth::collection_id_to_address(collection_id);228 Ok(address)229 }212230213 /// Check if a collection exists231 /// Check if a collection exists214 /// @param collection_address Address of the collection in question232 /// @param collection_address Address of the collection in question225243226/// 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 {primitives/data-structs/src/lib.rsdiffbeforeafterboth298 pub mode: CollectionMode,298 pub mode: CollectionMode,299 #[version(..2)]299 #[version(..2)]300 pub access: AccessMode,300 pub access: AccessMode,301 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,301 pub name: CollectionName,302 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,302 pub description: CollectionDescription,303 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,303 pub token_prefix: CollectionTokenPrefix,304304305 #[version(..2)]305 #[version(..2)]306 pub mint_mode: bool,306 pub mint_mode: bool,354 #[derivative(Default(value = "CollectionMode::NFT"))]354 #[derivative(Default(value = "CollectionMode::NFT"))]355 pub mode: CollectionMode,355 pub mode: CollectionMode,356 pub access: Option<AccessMode>,356 pub access: Option<AccessMode>,357 pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,357 pub name: CollectionName,358 pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,358 pub description: CollectionDescription,359 pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,359 pub token_prefix: CollectionTokenPrefix,360 pub pending_sponsor: Option<AccountId>,360 pub pending_sponsor: Option<AccountId>,361 pub limits: Option<CollectionLimits>,361 pub limits: Option<CollectionLimits>,362 pub permissions: Option<CollectionPermissions>,362 pub permissions: Option<CollectionPermissions>,tests/src/eth/createCollection.test.tsdiffbeforeafterboth27 getCollectionAddressFromResult,27 getCollectionAddressFromResult,28} from './util/helpers';28} from './util/helpers';292930describe('Create collection from EVM', () => {30describe.only('Create collection from EVM', () => {31 // itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {31 itWeb3('Create collection', async ({api, web3, privateKeyWrapper}) => {32 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);32 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);33 // const collectionHelper = evmCollectionHelpers(web3, owner);33 const collectionHelper = evmCollectionHelpers(web3, owner);34 // const collectionName = 'CollectionEVM';34 const collectionName = 'CollectionEVM';35 // const description = 'Some description';35 const description = 'Some description';36 // const tokenPrefix = 'token prefix';36 const tokenPrefix = 'token prefix';37 37 38 // const collectionCountBefore = await getCreatedCollectionCount(api);38 const collectionCountBefore = await getCreatedCollectionCount(api);39 // const result = await collectionHelper.methods39 const result = await collectionHelper.methods40 // .createNonfungibleCollection(collectionName, description, tokenPrefix)40 .createNonfungibleCollection(collectionName, description, tokenPrefix)41 // .send();41 .send();42 // const collectionCountAfter = await getCreatedCollectionCount(api);42 const collectionCountAfter = await getCreatedCollectionCount(api);43 43 44 // const {collectionId, collection} = await getCollectionAddressFromResult(api, result);44 const {collectionId, collection} = await getCollectionAddressFromResult(api, result);45 // expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);45 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);46 // expect(collectionId).to.be.eq(collectionCountAfter);46 expect(collectionId).to.be.eq(collectionCountAfter);47 // expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);47 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);48 // expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);48 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);49 // expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);49 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);50 // });50 });515152 // itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {52 itWeb3('Check collection address exist', async ({api, web3, privateKeyWrapper}) => {53 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);53 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);54 // const collectionHelpers = evmCollectionHelpers(web3, owner);54 const collectionHelpers = evmCollectionHelpers(web3, owner);55 55 56 // const expectedCollectionId = await getCreatedCollectionCount(api) + 1;56 const expectedCollectionId = await getCreatedCollectionCount(api) + 1;57 // const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);57 const expectedCollectionAddress = collectionIdToAddress(expectedCollectionId);58 // expect(await collectionHelpers.methods58 expect(await collectionHelpers.methods59 // .isCollectionExist(expectedCollectionAddress)59 .isCollectionExist(expectedCollectionAddress)60 // .call()).to.be.false;60 .call()).to.be.false;616162 // await collectionHelpers.methods62 await collectionHelpers.methods63 // .createNonfungibleCollection('A', 'A', 'A')63 .createNonfungibleCollection('A', 'A', 'A')64 // .send();64 .send();65 65 66 // expect(await collectionHelpers.methods66 expect(await collectionHelpers.methods67 // .isCollectionExist(expectedCollectionAddress)67 .isCollectionExist(expectedCollectionAddress)68 // .call()).to.be.true;68 .call()).to.be.true;69 // });69 });70 70 71 itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {71 itWeb3('Set sponsorship', async ({api, web3, privateKeyWrapper}) => {72 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);72 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);