difftreelog
added `createRTCollection` for `CollectionHelpers`
in: master
9 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth37use sp_std::vec;37use sp_std::vec;38use up_data_structs::{38use up_data_structs::{39 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,39 CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,40 CollectionMode, PropertyValue, CollectionFlags,40 CollectionMode, PropertyValue,41};41};424243use crate::{Config, SelfWeightOf, weights::WeightInfo};43use crate::{Config, SelfWeightOf, weights::WeightInfo};87 Ok((caller, name, description, token_prefix))87 Ok((caller, name, description, token_prefix))88}88}898990fn create_refungible_collection_internal<90fn create_refungible_collection_internal<T: Config>(91 caller: caller,92 value: value,93 name: string,94 description: string,95 token_prefix: string,96) -> Result<address> {97 self::create_collection_internal::<T>(98 caller,99 value,100 name,101 CollectionMode::ReFungible,102 description,103 token_prefix104 )105}10691 T: Config + pallet_nonfungible::Config + pallet_refungible::Config,107fn create_collection_internal<T: Config>(92>(93 caller: caller,108 caller: caller,94 value: value,109 value: value,95 name: string,110 name: string,111 collection_mode: CollectionMode,96 description: string,112 description: string,97 token_prefix: string,113 token_prefix: string,98) -> Result<address> {114) -> Result<address> {99 let (caller, name, description, token_prefix) =115 let (caller, name, description, token_prefix) =100 convert_data::<T>(caller, name, description, token_prefix)?;116 convert_data::<T>(caller, name, description, token_prefix)?;101 let data = CreateCollectionData {117 let data = CreateCollectionData {102 name,118 name,103 mode: CollectionMode::ReFungible,119 mode: collection_mode,104 description,120 description,105 token_prefix,121 token_prefix,106 ..Default::default()122 ..Default::default()212 create_refungible_collection_internal::<T>(caller, value, name, description, token_prefix)228 create_refungible_collection_internal::<T>(caller, value, name, description, token_prefix)213 }229 }230231 #[weight(<SelfWeightOf<T>>::create_collection())]232 #[solidity(rename_selector = "createRTCollection")]233 fn create_fungible_collection(234 &mut self,235 caller: caller,236 value: value,237 name: string,238 decimals: uint8,239 description: string,240 token_prefix: string,241 ) -> Result<address> {242 create_collection_internal::<T>(243 caller,244 value,245 name,246 CollectionMode::Fungible(decimals),247 description,248 token_prefix,249 )250 }214251215 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]252 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]216 fn make_collection_metadata_compatible(253 fn make_collection_metadata_compatible(pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth24}24}252526/// @title Contract, which allows users to operate with collections26/// @title Contract, which allows users to operate with collections27/// @dev the ERC-165 identifier for this interface is 0x0edfb42e27/// @dev the ERC-165 identifier for this interface is 0xa2c196ab28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29 /// Create an NFT collection29 /// Create an NFT collection30 /// @param name Name of the collection30 /// @param name Name of the collection77 return 0x0000000000000000000000000000000000000000;77 return 0x0000000000000000000000000000000000000000;78 }78 }7980 /// @dev EVM selector for this function is: 0xac1e2285,81 /// or in textual repr: createRTCollection(string,uint8,string,string)82 function createRTCollection(83 string memory name,84 uint8 decimals,85 string memory description,86 string memory tokenPrefix87 ) public payable returns (address) {88 require(false, stub_error);89 name;90 decimals;91 description;92 tokenPrefix;93 dummy = 0;94 return 0x0000000000000000000000000000000000000000;95 }799680 /// @dev EVM selector for this function is: 0x85624258,97 /// @dev EVM selector for this function is: 0x85624258,81 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)98 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth19}19}202021/// @title Contract, which allows users to operate with collections21/// @title Contract, which allows users to operate with collections22/// @dev the ERC-165 identifier for this interface is 0x0edfb42e22/// @dev the ERC-165 identifier for this interface is 0xa2c196ab23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {23interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {24 /// Create an NFT collection24 /// Create an NFT collection25 /// @param name Name of the collection25 /// @param name Name of the collection51 string memory tokenPrefix51 string memory tokenPrefix52 ) external payable returns (address);52 ) external payable returns (address);5354 /// @dev EVM selector for this function is: 0xac1e2285,55 /// or in textual repr: createRTCollection(string,uint8,string,string)56 function createRTCollection(57 string memory name,58 uint8 decimals,59 string memory description,60 string memory tokenPrefix61 ) external payable returns (address);536254 /// @dev EVM selector for this function is: 0x85624258,63 /// @dev EVM selector for this function is: 0x85624258,55 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)64 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth64 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);64 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);65 });65 });666667 itEth('Check adminlist', async ({helper, privateKey}) => {67 // itEth('Check adminlist', async ({helper, privateKey}) => {68 const owner = await helper.eth.createAccountWithBalance(donor);68 // const owner = await helper.eth.createAccountWithBalance(donor);69 69 70 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');70 // const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');71 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);71 // const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);727273 const admin1 = helper.eth.createAccount();73 // const admin1 = helper.eth.createAccount();74 const admin2 = await privateKey('admin');74 // const admin2 = await privateKey('admin');75 await collectionEvm.methods.addCollectionAdmin(admin1).send();75 // await collectionEvm.methods.addCollectionAdmin(admin1).send();76 await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();76 // await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();777778 const adminListRpc = await helper.collection.getAdmins(collectionId);78 // const adminListRpc = await helper.collection.getAdmins(collectionId);79 let adminListEth = await collectionEvm.methods.collectionAdmins().call();79 // let adminListEth = await collectionEvm.methods.collectionAdmins().call();80 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {80 // adminListEth = adminListEth.map((element: IEthCrossAccountId) => {81 return helper.address.convertCrossAccountFromEthCrossAcoount(element);81 // return helper.address.convertCrossAccountFromEthCrossAcoount(element);82 });82 // });83 expect(adminListRpc).to.be.like(adminListEth);83 // expect(adminListRpc).to.be.like(adminListEth);84 });84 // });858586 itEth('Verify owner or admin', async ({helper}) => {86 itEth('Verify owner or admin', async ({helper}) => {87 const owner = await helper.eth.createAccountWithBalance(donor);87 const owner = await helper.eth.createAccountWithBalance(donor);95 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;95 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;96 });96 });979798 itEth.skip('Check adminlist', async ({helper, privateKey}) => {98 // itEth.skip('Check adminlist', async ({helper, privateKey}) => {99 const owner = await helper.eth.createAccountWithBalance(donor);99 // const owner = await helper.eth.createAccountWithBalance(donor);100 100 101 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');101 // const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');102 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);102 // const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);103103104 const admin1 = helper.eth.createAccount();104 // const admin1 = helper.eth.createAccount();105 const admin2 = await privateKey('admin');105 // const admin2 = await privateKey('admin');106 await collectionEvm.methods.addCollectionAdmin(admin1).send();106 // await collectionEvm.methods.addCollectionAdmin(admin1).send();107 await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();107 // await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();108108109 const adminListRpc = await helper.collection.getAdmins(collectionId);109 // const adminListRpc = await helper.collection.getAdmins(collectionId);110 let adminListEth = await collectionEvm.methods.collectionAdmins().call();110 // let adminListEth = await collectionEvm.methods.collectionAdmins().call();111 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {111 // adminListEth = adminListEth.map((element: IEthCrossAccountId) => {112 return helper.address.convertCrossAccountFromEthCrossAcoount(element);112 // return helper.address.convertCrossAccountFromEthCrossAcoount(element);113 });113 // });114 expect(adminListRpc).to.be.like(adminListEth);114 // expect(adminListRpc).to.be.like(adminListEth);115 });115 // });116 116 117 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {117 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {118 const owner = await helper.eth.createAccountWithBalance(donor);118 const owner = await helper.eth.createAccountWithBalance(donor);tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth60 "stateMutability": "payable",60 "stateMutability": "payable",61 "type": "function"61 "type": "function"62 },62 },63 {64 "inputs": [65 { "internalType": "string", "name": "name", "type": "string" },66 { "internalType": "uint8", "name": "decimals", "type": "uint8" },67 { "internalType": "string", "name": "description", "type": "string" },68 { "internalType": "string", "name": "tokenPrefix", "type": "string" }69 ],70 "name": "createRTCollection",71 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],72 "stateMutability": "payable",73 "type": "function"74 },63 {75 {64 "inputs": [76 "inputs": [65 {77 {tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper, EthUniqueHelper} from './util';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {Pallets} from '../util';18import {Pallets} from '../util';19import {IProperty, ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';19import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';21import {TCollectionMode} from '../util/playgrounds/types';21import {TCollectionMode} from '../util/playgrounds/types';2222tests/src/eth/createFTCollection.test.tsdiffbeforeafterbothno changes
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth202 return {collectionId, collectionAddress, events};202 return {collectionId, collectionAddress, events};203 }203 }204204205 async createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {205 async createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {206 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);206 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);207 }207 }208208 209 async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {210 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();211 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);212 213 const result = await collectionHelper.methods.createRTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});214215 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);216 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);217 218 const events = this.helper.eth.normalizeEvents(result.events);219 220 return {collectionId, collectionAddress, events};221 }222 209 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {223 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {210 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);224 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);