From 4afba3743846bb3eb35248d36c3d60f3a6dd3763 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 28 Nov 2022 08:57:28 +0000 Subject: [PATCH] add `collectionComtractAddress` funtion to `CollectionHelpers` interface --- --- a/pallets/nonfungible/src/erc.rs +++ b/pallets/nonfungible/src/erc.rs @@ -490,8 +490,8 @@ // TODO: Not implemetable Err("not implemented".into()) } - - /// @notice Returns collection helper contract address + + /// @notice Returns collection helper contract address fn collection_helper_address(&self) -> Result
{ Ok(T::ContractAddress::get()) } --- a/pallets/refungible/src/erc.rs +++ b/pallets/refungible/src/erc.rs @@ -482,7 +482,7 @@ // TODO: Not implemetable Err("not implemented".into()) } - + /// @notice Returns collection helper contract address fn collection_helper_address(&self) -> Result
{ Ok(T::ContractAddress::get()) --- a/pallets/unique/src/eth/mod.rs +++ b/pallets/unique/src/eth/mod.rs @@ -28,6 +28,7 @@ CollectionById, dispatch::CollectionDispatch, erc::{CollectionHelpersEvents, static_property::key}, + eth::{map_eth_to_id, collection_id_to_address}, Pallet as PalletCommon, }; use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult}; @@ -35,7 +36,7 @@ use sp_std::vec; use up_data_structs::{ CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix, - CreateCollectionData, + CreateCollectionData, CollectionId, }; use crate::{weights::WeightInfo, Config, SelfWeightOf}; @@ -361,6 +362,25 @@ .expect("Collection creation price should be convertible to u128"); Ok(price.into()) } + + /// Returns address of a collection. + /// @param collectionId - CollectionId of the collection + /// @return eth mirror address of the collection + fn collection_address(&self, collection_id: uint32) -> Result
{ + Ok(collection_id_to_address(collection_id.into())) + } + + /// Returns collectionId of a collection. + /// @param collectionAddress - Eth address of the collection + /// @return collectionId of the collection + fn collection_id(&self, collection_address: address) -> Result { + map_eth_to_id(&collection_address) + .map(|id| id.0) + .ok_or(Error::Revert(format!( + "failed to convert address {} into collectionId.", + collection_address + ))) + } } /// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`] --- 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 0x7dea03b1 +/// @dev the ERC-165 identifier for this interface is 0xe65011aa contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents { /// Create an NFT collection /// @param name Name of the collection @@ -130,4 +130,28 @@ dummy; return 0; } + + /// Returns address of a collection. + /// @param collectionId - CollectionId of the collection + /// @return eth mirror address of the collection + /// @dev EVM selector for this function is: 0x2e716683, + /// or in textual repr: collectionAddress(uint32) + function collectionAddress(uint32 collectionId) public view returns (address) { + require(false, stub_error); + collectionId; + dummy; + return 0x0000000000000000000000000000000000000000; + } + + /// Returns collectionId of a collection. + /// @param collectionAddress - Eth address of the collection + /// @return collectionId of the collection + /// @dev EVM selector for this function is: 0xb5cb7498, + /// or in textual repr: collectionId(address) + function collectionId(address collectionAddress) public view returns (uint32) { + require(false, stub_error); + collectionAddress; + dummy; + return 0; + } } --- a/tests/src/eth/abi/collectionHelpers.json +++ b/tests/src/eth/abi/collectionHelpers.json @@ -32,6 +32,15 @@ "type": "event" }, { + "inputs": [ + { "internalType": "uint32", "name": "collectionId", "type": "uint32" } + ], + "name": "collectionAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "collectionCreationFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], @@ -40,6 +49,19 @@ }, { "inputs": [ + { + "internalType": "address", + "name": "collectionAddress", + "type": "address" + } + ], + "name": "collectionId", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "uint8", "name": "decimals", "type": "uint8" }, { "internalType": "string", "name": "description", "type": "string" }, --- 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 0x7dea03b1 +/// @dev the ERC-165 identifier for this interface is 0xe65011aa interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents { /// Create an NFT collection /// @param name Name of the collection @@ -78,4 +78,18 @@ /// @dev EVM selector for this function is: 0xd23a7ab1, /// or in textual repr: collectionCreationFee() function collectionCreationFee() external view returns (uint256); + + /// Returns address of a collection. + /// @param collectionId - CollectionId of the collection + /// @return eth mirror address of the collection + /// @dev EVM selector for this function is: 0x2e716683, + /// or in textual repr: collectionAddress(uint32) + function collectionAddress(uint32 collectionId) external view returns (address); + + /// Returns collectionId of a collection. + /// @param collectionAddress - Eth address of the collection + /// @return collectionId of the collection + /// @dev EVM selector for this function is: 0xb5cb7498, + /// or in textual repr: collectionId(address) + function collectionId(address collectionAddress) external view returns (uint32); } --- a/tests/src/eth/collectionHelperAddress.test.ts +++ b/tests/src/eth/collectionHelperAddress.test.ts @@ -16,10 +16,11 @@ import {itEth, usingEthPlaygrounds, expect} from './util'; import {IKeyringPair} from '@polkadot/types/types'; +import {Pallets} from '../util'; const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f'; -describe('[eth]CollectionHelerpAddress test: ERC721 ', () => { +describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => { let donor: IKeyringPair; before(async function() { @@ -28,18 +29,22 @@ }); }); - itEth('NFT\\RFT', async ({helper}) => { + itEth('NFT', async ({helper}) => { const owner = await helper.eth.createAccountWithBalance(donor); const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC'); const nftCollection = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner); - - const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC'); - const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner); expect((await nftCollection.methods.collectionHelperAddress().call()) .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); - + }); + + itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + + const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC'); + + const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner); expect((await rftCollection.methods.collectionHelperAddress().call()) .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); }); @@ -53,5 +58,15 @@ expect((await collection.methods.collectionHelperAddress().call()) .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); }); + + itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const collectionId = 7; + const collectionAddress = helper.ethAddress.fromCollectionId(collectionId); + const helperContract = helper.ethNativeContract.collectionHelpers(owner); + + expect(await helperContract.methods.collectionAddress(collectionId).call()).to.be.equal(collectionAddress); + expect(parseInt(await helperContract.methods.collectionId(collectionAddress).call())).to.be.equal(collectionId); + }); }); --- a/tests/src/interfaces/lookup.ts +++ b/tests/src/interfaces/lookup.ts @@ -2936,13 +2936,13 @@ } }, /** - * Lookup338: pallet_maintenance::pallet::Call + * Lookup340: pallet_maintenance::pallet::Call **/ PalletMaintenanceCall: { _enum: ['enable', 'disable'] }, /** - * Lookup339: pallet_test_utils::pallet::Call + * Lookup341: pallet_test_utils::pallet::Call **/ PalletTestUtilsCall: { _enum: { --- a/tests/src/interfaces/types-lookup.ts +++ b/tests/src/interfaces/types-lookup.ts @@ -3175,14 +3175,14 @@ readonly type: 'Begin' | 'SetData' | 'Finish' | 'InsertEthLogs' | 'InsertEvents'; } - /** @name PalletMaintenanceCall (338) */ + /** @name PalletMaintenanceCall (340) */ interface PalletMaintenanceCall extends Enum { readonly isEnable: boolean; readonly isDisable: boolean; readonly type: 'Enable' | 'Disable'; } - /** @name PalletTestUtilsCall (339) */ + /** @name PalletTestUtilsCall (341) */ interface PalletTestUtilsCall extends Enum { readonly isEnable: boolean; readonly isSetTestValue: boolean; -- gitstuff