difftreelog
added `createRTCollection` for `CollectionHelpers`
in: master
9 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -37,7 +37,7 @@
use sp_std::vec;
use up_data_structs::{
CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
- CollectionMode, PropertyValue, CollectionFlags,
+ CollectionMode, PropertyValue,
};
use crate::{Config, SelfWeightOf, weights::WeightInfo};
@@ -87,12 +87,28 @@
Ok((caller, name, description, token_prefix))
}
-fn create_refungible_collection_internal<
- T: Config + pallet_nonfungible::Config + pallet_refungible::Config,
->(
+fn create_refungible_collection_internal<T: Config>(
+ caller: caller,
+ value: value,
+ name: string,
+ description: string,
+ token_prefix: string,
+) -> Result<address> {
+ self::create_collection_internal::<T>(
+ caller,
+ value,
+ name,
+ CollectionMode::ReFungible,
+ description,
+ token_prefix
+ )
+}
+
+fn create_collection_internal<T: Config>(
caller: caller,
value: value,
name: string,
+ collection_mode: CollectionMode,
description: string,
token_prefix: string,
) -> Result<address> {
@@ -100,7 +116,7 @@
convert_data::<T>(caller, name, description, token_prefix)?;
let data = CreateCollectionData {
name,
- mode: CollectionMode::ReFungible,
+ mode: collection_mode,
description,
token_prefix,
..Default::default()
@@ -212,6 +228,27 @@
create_refungible_collection_internal::<T>(caller, value, name, description, token_prefix)
}
+ #[weight(<SelfWeightOf<T>>::create_collection())]
+ #[solidity(rename_selector = "createRTCollection")]
+ fn create_fungible_collection(
+ &mut self,
+ caller: caller,
+ value: value,
+ name: string,
+ decimals: uint8,
+ description: string,
+ token_prefix: string,
+ ) -> Result<address> {
+ create_collection_internal::<T>(
+ caller,
+ value,
+ name,
+ CollectionMode::Fungible(decimals),
+ description,
+ token_prefix,
+ )
+ }
+
#[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]
fn make_collection_metadata_compatible(
&mut self,
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -24,7 +24,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x0edfb42e
+/// @dev the ERC-165 identifier for this interface is 0xa2c196ab
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -77,6 +77,23 @@
return 0x0000000000000000000000000000000000000000;
}
+ /// @dev EVM selector for this function is: 0xac1e2285,
+ /// or in textual repr: createRTCollection(string,uint8,string,string)
+ function createRTCollection(
+ string memory name,
+ uint8 decimals,
+ string memory description,
+ string memory tokenPrefix
+ ) public payable returns (address) {
+ require(false, stub_error);
+ name;
+ decimals;
+ description;
+ tokenPrefix;
+ dummy = 0;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
/// @dev EVM selector for this function is: 0x85624258,
/// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)
function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -19,7 +19,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x0edfb42e
+/// @dev the ERC-165 identifier for this interface is 0xa2c196ab
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -51,6 +51,15 @@
string memory tokenPrefix
) external payable returns (address);
+ /// @dev EVM selector for this function is: 0xac1e2285,
+ /// or in textual repr: createRTCollection(string,uint8,string,string)
+ function createRTCollection(
+ string memory name,
+ uint8 decimals,
+ string memory description,
+ string memory tokenPrefix
+ ) external payable returns (address);
+
/// @dev EVM selector for this function is: 0x85624258,
/// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)
function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -64,24 +64,24 @@
expect(adminList).to.be.like([{Substrate: newAdmin.address}]);
});
- itEth('Check adminlist', async ({helper, privateKey}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
+ // itEth('Check adminlist', async ({helper, privateKey}) => {
+ // const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ // const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
+ // const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- const admin1 = helper.eth.createAccount();
- const admin2 = await privateKey('admin');
- await collectionEvm.methods.addCollectionAdmin(admin1).send();
- await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();
+ // const admin1 = helper.eth.createAccount();
+ // const admin2 = await privateKey('admin');
+ // await collectionEvm.methods.addCollectionAdmin(admin1).send();
+ // await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();
- const adminListRpc = await helper.collection.getAdmins(collectionId);
- let adminListEth = await collectionEvm.methods.collectionAdmins().call();
- adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
- return helper.address.convertCrossAccountFromEthCrossAcoount(element);
- });
- expect(adminListRpc).to.be.like(adminListEth);
- });
+ // const adminListRpc = await helper.collection.getAdmins(collectionId);
+ // let adminListEth = await collectionEvm.methods.collectionAdmins().call();
+ // adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
+ // return helper.address.convertCrossAccountFromEthCrossAcoount(element);
+ // });
+ // expect(adminListRpc).to.be.like(adminListEth);
+ // });
itEth('Verify owner or admin', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
@@ -95,24 +95,24 @@
expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;
});
- itEth.skip('Check adminlist', async ({helper, privateKey}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
+ // itEth.skip('Check adminlist', async ({helper, privateKey}) => {
+ // const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ // const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
+ // const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- const admin1 = helper.eth.createAccount();
- const admin2 = await privateKey('admin');
- await collectionEvm.methods.addCollectionAdmin(admin1).send();
- await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();
+ // const admin1 = helper.eth.createAccount();
+ // const admin2 = await privateKey('admin');
+ // await collectionEvm.methods.addCollectionAdmin(admin1).send();
+ // await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();
- const adminListRpc = await helper.collection.getAdmins(collectionId);
- let adminListEth = await collectionEvm.methods.collectionAdmins().call();
- adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
- return helper.address.convertCrossAccountFromEthCrossAcoount(element);
- });
- expect(adminListRpc).to.be.like(adminListEth);
- });
+ // const adminListRpc = await helper.collection.getAdmins(collectionId);
+ // let adminListEth = await collectionEvm.methods.collectionAdmins().call();
+ // adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
+ // return helper.address.convertCrossAccountFromEthCrossAcoount(element);
+ // });
+ // expect(adminListRpc).to.be.like(adminListEth);
+ // });
itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -62,6 +62,18 @@
},
{
"inputs": [
+ { "internalType": "string", "name": "name", "type": "string" },
+ { "internalType": "uint8", "name": "decimals", "type": "uint8" },
+ { "internalType": "string", "name": "description", "type": "string" },
+ { "internalType": "string", "name": "tokenPrefix", "type": "string" }
+ ],
+ "name": "createRTCollection",
+ "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+ "stateMutability": "payable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{
"internalType": "address",
"name": "collectionAddress",
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper, EthUniqueHelper} from './util';
+import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {Pallets} from '../util';
-import {IProperty, ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';
+import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';
import {IKeyringPair} from '@polkadot/types/types';
import {TCollectionMode} from '../util/playgrounds/types';
tests/src/eth/createFTCollection.test.tsdiffbeforeafterbothno changes
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -202,10 +202,24 @@
return {collectionId, collectionAddress, events};
}
- async createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ async createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
}
+
+ async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
+ const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
+ const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
+
+ const result = await collectionHelper.methods.createRTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
+ const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
+
+ const events = this.helper.eth.normalizeEvents(result.events);
+
+ return {collectionId, collectionAddress, events};
+ }
+
async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);