--- 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", --- 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' } --- a/pallets/unique/src/eth/mod.rs +++ b/pallets/unique/src/eth/mod.rs @@ -210,6 +210,24 @@ Ok(address) } + #[weight(>::create_collection())] + fn create_refungible_collection( + &self, + caller: caller, + name: string, + description: string, + token_prefix: string, + ) -> Result
{ + let (caller, name, description, token_prefix) = + convert_data::(caller, name, description, token_prefix)?; + let data = make_data::(name, description, token_prefix)?; + let collection_id = >::init_collection(caller.clone(), data) + .map_err(pallet_evm_coder_substrate::dispatch_to_evm::)?; + + let address = pallet_common::eth::collection_id_to_address(collection_id); + Ok(address) + } + /// Check if a collection exists /// @param collection_address Address of the collection in question /// @return bool Does the collection exist? @@ -225,7 +243,9 @@ /// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`] pub struct CollectionHelpersOnMethodCall(PhantomData<*const T>); -impl OnMethodCall for CollectionHelpersOnMethodCall { +impl OnMethodCall + for CollectionHelpersOnMethodCall +{ fn is_reserved(contract: &sp_core::H160) -> bool { contract == &T::ContractAddress::get() } --- 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>, - pub description: BoundedVec>, - pub token_prefix: BoundedVec>, + 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, - pub name: BoundedVec>, - pub description: BoundedVec>, - pub token_prefix: BoundedVec>, + pub name: CollectionName, + pub description: CollectionDescription, + pub token_prefix: CollectionTokenPrefix, pub pending_sponsor: Option, pub limits: Option, pub permissions: Option, --- 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);