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.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' }
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -210,6 +210,24 @@
Ok(address)
}
+ #[weight(<SelfWeightOf<T>>::create_collection())]
+ fn create_refungible_collection(
+ &self,
+ caller: caller,
+ name: string,
+ description: string,
+ token_prefix: string,
+ ) -> Result<address> {
+ let (caller, name, description, token_prefix) =
+ convert_data::<T>(caller, name, description, token_prefix)?;
+ let data = make_data::<T>(name, description, token_prefix)?;
+ let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)
+ .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+
+ 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<T: Config>(PhantomData<*const T>);
-impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {
+impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>
+ for CollectionHelpersOnMethodCall<T>
+{
fn is_reserved(contract: &sp_core::H160) -> bool {
contract == &T::ContractAddress::get()
}
primitives/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>,
tests/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);