difftreelog
added coderTest via Conract
in: master
4 files changed
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
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+/// @dev common stubs holder
+contract Dummy {
+ uint8 dummy;
+ string stub_error = "this contract is implemented in native";
+}
+
+contract ERC165 is Dummy {
+ function supportsInterface(bytes4 interfaceID) external view returns (bool) {
+ require(false, stub_error);
+ interfaceID;
+ return true;
+ }
+}
+
+/// @dev inlined interface
+contract CollectionHelpersEvents {
+ event CollectionCreated(address indexed owner, address indexed collectionId);
+ event CollectionDestroyed(address indexed collectionId);
+}
+
+/// @title Contract, which allows users to operate with collections
+/// @dev the ERC-165 identifier for this interface is 0x7dea03b1
+contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
+ /// Create an NFT collection
+ /// @param name Name of the collection
+ /// @param description Informative description of the collection
+ /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications
+ /// @return address Address of the newly created collection
+ /// @dev EVM selector for this function is: 0x844af658,
+ /// or in textual repr: createNFTCollection(string,string,string)
+ function createNFTCollection(
+ string memory name,
+ string memory description,
+ string memory tokenPrefix
+ ) public payable returns (address) {
+ require(false, stub_error);
+ name;
+ description;
+ tokenPrefix;
+ dummy = 0;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ // /// Create an NFT collection
+ // /// @param name Name of the collection
+ // /// @param description Informative description of the collection
+ // /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications
+ // /// @return address Address of the newly created collection
+ // /// @dev EVM selector for this function is: 0xe34a6844,
+ // /// or in textual repr: createNonfungibleCollection(string,string,string)
+ // function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {
+ // require(false, stub_error);
+ // name;
+ // description;
+ // tokenPrefix;
+ // dummy = 0;
+ // return 0x0000000000000000000000000000000000000000;
+ // }
+
+ /// @dev EVM selector for this function is: 0xab173450,
+ /// or in textual repr: createRFTCollection(string,string,string)
+ function createRFTCollection(
+ string memory name,
+ string memory description,
+ string memory tokenPrefix
+ ) public payable returns (address) {
+ require(false, stub_error);
+ name;
+ description;
+ tokenPrefix;
+ dummy = 0;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ /// @dev EVM selector for this function is: 0x7335b79f,
+ /// or in textual repr: createFTCollection(string,uint8,string,string)
+ function createFTCollection(
+ 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 {
+ require(false, stub_error);
+ collection;
+ baseUri;
+ dummy = 0;
+ }
+
+ /// @dev EVM selector for this function is: 0x564e321f,
+ /// or in textual repr: destroyCollection(address)
+ function destroyCollection(address collectionAddress) public {
+ require(false, stub_error);
+ collectionAddress;
+ dummy = 0;
+ }
+
+ /// Check if a collection exists
+ /// @param collectionAddress Address of the collection in question
+ /// @return bool Does the collection exist?
+ /// @dev EVM selector for this function is: 0xc3de1494,
+ /// or in textual repr: isCollectionExist(address)
+ function isCollectionExist(address collectionAddress) public view returns (bool) {
+ require(false, stub_error);
+ collectionAddress;
+ dummy;
+ return false;
+ }
+
+ /// @dev EVM selector for this function is: 0xd23a7ab1,
+ /// or in textual repr: collectionCreationFee()
+ function collectionCreationFee() public view returns (uint256) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+}
tests/src/eth/evmToSubstrate/EvmToSubstrateHelper.soldiffbeforeafterboth--- a/tests/src/eth/evmToSubstrate/EvmToSubstrateHelper.sol
+++ b/tests/src/eth/evmToSubstrate/EvmToSubstrateHelper.sol
@@ -68,7 +68,7 @@
if (collectionType == REFUNGIBLE_COLLECTION_TYPE) {
UniqueRefungible rftCollection = UniqueRefungible(_collection);
-
+
tokenId = rftCollection.mint(address(this));
rftCollection.transferFromCross(
@@ -176,4 +176,27 @@
emit MintToSub(address(0), _substrateReceiver, _collection, tokenId);
}
+
+ function proxyProperties(
+ address _collection,
+ uint256 _tokenId,
+ NftProperty[] calldata _properties
+ ) external checkRestrictions(_collection) {
+ uint256 propertiesLength = _properties.length;
+ require(propertiesLength > 0, "Properies is empty");
+
+ Collection commonContract = Collection(_collection);
+ bytes32 collectionType = keccak256(bytes(commonContract.uniqueCollectionType()));
+
+ if (collectionType == REFUNGIBLE_COLLECTION_TYPE) {
+ revert("Wrong collection type. Works only with NFT or RFT");
+ } else if (collectionType == NONFUNGIBLE_COLLECTION_TYPE) {
+ UniqueNFT nftCollection = UniqueNFT(_collection);
+
+
+ nftCollection.setProperties(_tokenId, _properties);
+ } else {
+ revert("Wrong collection type. Works only with NFT or RFT");
+ }
+ }
}
tests/src/eth/evmToSubstrate/coderTest.tsdiffbeforeafterboth1import { EthUniqueHelper, usingEthPlaygrounds } from '../util';2import { readFile } from 'fs/promises';3import { ContractImports } from '../util/playgrounds/types';4import { Contract } from '@polkadot/api-contract/base';5import Web3 from 'web3';6import {7 IProperty,8 ITokenPropertyPermission,9} from '../../util/playgrounds/types';10import { addressToEvm, decodeAddress } from '@polkadot/util-crypto';11import nonFungibleAbi from '../nonFungibleAbi.json';12import { IKeyringPair } from '@polkadot/types/types';1314enum SponsoringMode {15 Disabled = 0,16 Allowlisted = 1,17 Generous = 2,18}1920const WS_ENDPOINT = 'wss://ws-rc.unique.network';21const CONTRACT_IMPORT: ContractImports[] = [22 {23 fsPath: `${__dirname}/../api/CollectionHelpers.sol`,24 solPath: 'api/CollectionHelpers.sol',25 },26 {27 fsPath: `${__dirname}/../api/ContractHelpers.sol`,28 solPath: 'api/ContractHelpers.sol',29 },30 {31 fsPath: `${__dirname}/../api/UniqueRefungibleToken.sol`,32 solPath: 'api/UniqueRefungibleToken.sol',33 },34 {35 fsPath: `${__dirname}/../api/UniqueRefungible.sol`,36 solPath: 'api/UniqueRefungible.sol',37 },38 {39 fsPath: `${__dirname}/../api/UniqueNFT.sol`,40 solPath: 'api/UniqueNFT.sol',41 },42];4344const main = async () => {45 await usingEthPlaygrounds(async (helper, privateKey) => {46 const contract_source = (47 await readFile(`${__dirname}/EvmToSubstrateHelper.sol`)48 ).toString();4950 const donor = await privateKey('//Alice'); // Seed from account with balance on this network51 const myAccount = await privateKey('//Bob'); // replace with account from polkadot extension52 const signer = await helper.eth.createAccountWithBalance(donor, 100n);53 console.log(`signer data: ${Uint8Array.from(Buffer.from(signer.slice(2),'hex'))}`)54 const collection = await helper.nft.mintCollection(donor, {55 name: 'test mintToSubstrate',56 description: 'EVMHelpers',57 tokenPrefix: 'ap',58 tokenPropertyPermissions: [59 {60 key: 'url',61 permission: {62 tokenOwner: true,63 collectionAdmin: true,64 mutable: true,65 },66 },67 ],68 limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },69 permissions: { mintMode: true },70 });7172 await collection.addToAllowList(donor, {73 Ethereum: helper.address.substrateToEth(donor.address),74 });75 await collection.addToAllowList(donor, { Substrate: donor.address });76 await collection.addAdmin(donor, { Ethereum: signer });77 await collection.addAdmin(donor, {78 Ethereum: helper.address.substrateToEth(donor.address),79 });8081 console.log('collection admin(s)): ', await collection.getAdmins());82 console.log('collection owner(s)): ', await collection.getAllowList());8384 const collectionEthAddress = helper.ethAddress.fromCollectionId(85 collection.collectionId,86 );8788 const collectionEthContract = helper.ethNativeContract.collection(89 collectionEthAddress,90 'nft',91 );9293 const receiverEthAddress = helper.address.substrateToEth(myAccount.address);94 95 const contract = await helper.ethContract.deployByCode(96 signer,97 'EvmToSubstrate',98 contract_source,99 CONTRACT_IMPORT,100 );101 console.log(`contract has been deployed\naddres: ${contract.options.address} || ${Uint8Array.from(Buffer.from(contract.options.address.slice(2),'hex'))}`);102103 await helper.eth.transferBalanceFromSubstrate(104 donor,105 contract.options.address,106 100n,107 );108109 console.log(`transfer has been completed`);110111 await collection.addToAllowList(donor, {112 Ethereum: contract.options.address,113 });114 await collection.addAdmin(donor, { Ethereum: contract.options.address });115116 console.log(`setup has been completed`);117118 console.log('\t\t\t *** Properties Fees ***\n');119120 const propertiesNumber = 20;121122 const properties = Array(40)123 .fill(0)124 .map((_, i) => {125 return {126 key: `key_${i}`,127 value: Uint8Array.from(Buffer.from(`value_${i}`)),128 };129 });130131 const permissions: ITokenPropertyPermission[] = properties.map((p) => {132 return {133 key: p.key,134 permission: {135 tokenOwner: true,136 collectionAdmin: true,137 mutable: true,138 },139 };140 });141142 // *** ProxyContract Bulk ***143144 const token = await collection.mintToken(donor, { Ethereum: signer });145146 const mintWithBulkPropProxyContractFee = await helper.arrange.calculcateFee(147 { Ethereum: signer },148 async () => {149 await contract.methods150 .proxyProperties(151 collectionEthContract.options.address,152 token.tokenId,153 properties.slice(0, propertiesNumber).map((p) => {154 return { field_0: p.key, field_1: p.value };155 }),156 )157 .send({ from: signer });158 },159 );160 console.log(161 `token mint from contract(with bulk prop.) to the Substrate Id: ${mintWithBulkPropProxyContractFee}`,162 );163164 console.log('All done');165 });166};167168main()169 .then(() => process.exit(0))170 .catch((e) => {171 console.log(e);172 process.exit(1);173 });174175async function createCollectionForPropertiesBenchmarks(176 helper: EthUniqueHelper,177 privateKey: (seed: string) => Promise<IKeyringPair>,178 ethSigner: string,179 proxyContract: string,180 permissions: ITokenPropertyPermission[],181) {182 const donor = await privateKey('//Alice'); // Seed from account with balance on this network183184 const collection = await helper.nft.mintCollection(donor, {185 name: 'test mintToSubstrate',186 description: 'EVMHelpers',187 tokenPrefix: 'ap',188 tokenPropertyPermissions: [189 {190 key: 'url',191 permission: {192 tokenOwner: true,193 collectionAdmin: true,194 mutable: true,195 },196 },197 ],198 limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },199 permissions: { mintMode: true },200 });201202 await collection.addToAllowList(donor, {203 Ethereum: helper.address.substrateToEth(donor.address),204 });205 await collection.addToAllowList(donor, { Substrate: donor.address });206 await collection.addAdmin(donor, { Ethereum: ethSigner });207 await collection.addAdmin(donor, {208 Ethereum: helper.address.substrateToEth(donor.address),209 });210 await collection.addToAllowList(donor, { Ethereum: proxyContract });211 await collection.addAdmin(donor, { Ethereum: proxyContract });212 await collection.setTokenPropertyPermissions(donor, permissions);213214 return collection;215}