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.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8 uint8 dummy;9 string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13 function supportsInterface(bytes4 interfaceID) external view returns (bool) {14 require(false, stub_error);15 interfaceID;16 return true;17 }18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22 event CollectionCreated(address indexed owner, address indexed collectionId);23 event CollectionDestroyed(address indexed collectionId);24}2526/// @title Contract, which allows users to operate with collections27/// @dev the ERC-165 identifier for this interface is 0x7dea03b128contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {29 /// Create an NFT collection30 /// @param name Name of the collection31 /// @param description Informative description of the collection32 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications33 /// @return address Address of the newly created collection34 /// @dev EVM selector for this function is: 0x844af658,35 /// or in textual repr: createNFTCollection(string,string,string)36 function createNFTCollection(37 string memory name,38 string memory description,39 string memory tokenPrefix40 ) public payable returns (address) {41 require(false, stub_error);42 name;43 description;44 tokenPrefix;45 dummy = 0;46 return 0x0000000000000000000000000000000000000000;47 }4849 // /// Create an NFT collection50 // /// @param name Name of the collection51 // /// @param description Informative description of the collection52 // /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications53 // /// @return address Address of the newly created collection54 // /// @dev EVM selector for this function is: 0xe34a6844,55 // /// or in textual repr: createNonfungibleCollection(string,string,string)56 // function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) public payable returns (address) {57 // require(false, stub_error);58 // name;59 // description;60 // tokenPrefix;61 // dummy = 0;62 // return 0x0000000000000000000000000000000000000000;63 // }6465 /// @dev EVM selector for this function is: 0xab173450,66 /// or in textual repr: createRFTCollection(string,string,string)67 function createRFTCollection(68 string memory name,69 string memory description,70 string memory tokenPrefix71 ) public payable returns (address) {72 require(false, stub_error);73 name;74 description;75 tokenPrefix;76 dummy = 0;77 return 0x0000000000000000000000000000000000000000;78 }7980 /// @dev EVM selector for this function is: 0x7335b79f,81 /// or in textual repr: createFTCollection(string,uint8,string,string)82 function createFTCollection(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 }9697 /// @dev EVM selector for this function is: 0x85624258,98 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)99 function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) public {100 require(false, stub_error);101 collection;102 baseUri;103 dummy = 0;104 }105106 /// @dev EVM selector for this function is: 0x564e321f,107 /// or in textual repr: destroyCollection(address)108 function destroyCollection(address collectionAddress) public {109 require(false, stub_error);110 collectionAddress;111 dummy = 0;112 }113114 /// Check if a collection exists115 /// @param collectionAddress Address of the collection in question116 /// @return bool Does the collection exist?117 /// @dev EVM selector for this function is: 0xc3de1494,118 /// or in textual repr: isCollectionExist(address)119 function isCollectionExist(address collectionAddress) public view returns (bool) {120 require(false, stub_error);121 collectionAddress;122 dummy;123 return false;124 }125126 /// @dev EVM selector for this function is: 0xd23a7ab1,127 /// or in textual repr: collectionCreationFee()128 function collectionCreationFee() public view returns (uint256) {129 require(false, stub_error);130 dummy;131 return 0;132 }133}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.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/evmToSubstrate/coderTest.ts
@@ -0,0 +1,215 @@
+import { EthUniqueHelper, usingEthPlaygrounds } from '../util';
+import { readFile } from 'fs/promises';
+import { ContractImports } from '../util/playgrounds/types';
+import { Contract } from '@polkadot/api-contract/base';
+import Web3 from 'web3';
+import {
+ IProperty,
+ ITokenPropertyPermission,
+} from '../../util/playgrounds/types';
+import { addressToEvm, decodeAddress } from '@polkadot/util-crypto';
+import nonFungibleAbi from '../nonFungibleAbi.json';
+import { IKeyringPair } from '@polkadot/types/types';
+
+enum SponsoringMode {
+ Disabled = 0,
+ Allowlisted = 1,
+ Generous = 2,
+}
+
+const WS_ENDPOINT = 'wss://ws-rc.unique.network';
+const CONTRACT_IMPORT: ContractImports[] = [
+ {
+ fsPath: `${__dirname}/../api/CollectionHelpers.sol`,
+ solPath: 'api/CollectionHelpers.sol',
+ },
+ {
+ fsPath: `${__dirname}/../api/ContractHelpers.sol`,
+ solPath: 'api/ContractHelpers.sol',
+ },
+ {
+ fsPath: `${__dirname}/../api/UniqueRefungibleToken.sol`,
+ solPath: 'api/UniqueRefungibleToken.sol',
+ },
+ {
+ fsPath: `${__dirname}/../api/UniqueRefungible.sol`,
+ solPath: 'api/UniqueRefungible.sol',
+ },
+ {
+ fsPath: `${__dirname}/../api/UniqueNFT.sol`,
+ solPath: 'api/UniqueNFT.sol',
+ },
+];
+
+const main = async () => {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ const contract_source = (
+ await readFile(`${__dirname}/EvmToSubstrateHelper.sol`)
+ ).toString();
+
+ const donor = await privateKey('//Alice'); // Seed from account with balance on this network
+ const myAccount = await privateKey('//Bob'); // replace with account from polkadot extension
+ const signer = await helper.eth.createAccountWithBalance(donor, 100n);
+ console.log(`signer data: ${Uint8Array.from(Buffer.from(signer.slice(2), 'hex'))}`)
+ const collection = await helper.nft.mintCollection(donor, {
+ name: 'test mintToSubstrate',
+ description: 'EVMHelpers',
+ tokenPrefix: 'ap',
+ tokenPropertyPermissions: [
+ {
+ key: 'url',
+ permission: {
+ tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true,
+ },
+ },
+ ],
+ limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },
+ permissions: { mintMode: true },
+ });
+
+ await collection.addToAllowList(donor, {
+ Ethereum: helper.address.substrateToEth(donor.address),
+ });
+ await collection.addToAllowList(donor, { Substrate: donor.address });
+ await collection.addAdmin(donor, { Ethereum: signer });
+ await collection.addAdmin(donor, {
+ Ethereum: helper.address.substrateToEth(donor.address),
+ });
+
+ console.log('collection admin(s)): ', await collection.getAdmins());
+ console.log('collection owner(s)): ', await collection.getAllowList());
+
+ const collectionEthAddress = helper.ethAddress.fromCollectionId(
+ collection.collectionId,
+ );
+
+ const collectionEthContract = helper.ethNativeContract.collection(
+ collectionEthAddress,
+ 'nft',
+ );
+
+ const receiverEthAddress = helper.address.substrateToEth(myAccount.address);
+
+ const contract = await helper.ethContract.deployByCode(
+ signer,
+ 'EvmToSubstrate',
+ contract_source,
+ CONTRACT_IMPORT,
+ );
+ console.log(`contract has been deployed\naddres: ${contract.options.address} || ${Uint8Array.from(Buffer.from(contract.options.address.slice(2), 'hex'))}`);
+
+ await helper.eth.transferBalanceFromSubstrate(
+ donor,
+ contract.options.address,
+ 100n,
+ );
+
+ console.log(`transfer has been completed`);
+
+ await collection.addToAllowList(donor, {
+ Ethereum: contract.options.address,
+ });
+ await collection.addAdmin(donor, { Ethereum: contract.options.address });
+
+ console.log(`setup has been completed`);
+
+ console.log('\t\t\t *** Properties Fees ***\n');
+
+ const propertiesNumber = 20;
+
+ const properties = Array(40)
+ .fill(0)
+ .map((_, i) => {
+ return {
+ key: `key_${i}`,
+ value: Uint8Array.from(Buffer.from(`value_${i}`)),
+ };
+ });
+
+ const permissions: ITokenPropertyPermission[] = properties.map((p) => {
+ return {
+ key: p.key,
+ permission: {
+ tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true,
+ },
+ };
+ });
+
+ // *** ProxyContract Bulk ***
+
+ const token = await collection.mintToken(donor, { Ethereum: signer });
+
+ const mintWithBulkPropProxyContractFee = await helper.arrange.calculcateFee(
+ { Ethereum: signer },
+ async () => {
+ await contract.methods
+ .proxyProperties(
+ collectionEthContract.options.address,
+ token.tokenId,
+ properties.slice(0, propertiesNumber).map((p) => {
+ return { field_0: p.key, field_1: p.value };
+ }),
+ )
+ .send({ from: signer });
+ },
+ );
+ console.log(
+ `token mint from contract(with bulk prop.) to the Substrate Id: ${mintWithBulkPropProxyContractFee}`,
+ );
+
+ console.log('All done');
+ });
+};
+
+main()
+ .then(() => process.exit(0))
+ .catch((e) => {
+ console.log(e);
+ process.exit(1);
+ });
+
+async function createCollectionForPropertiesBenchmarks(
+ helper: EthUniqueHelper,
+ privateKey: (seed: string) => Promise<IKeyringPair>,
+ ethSigner: string,
+ proxyContract: string,
+ permissions: ITokenPropertyPermission[],
+) {
+ const donor = await privateKey('//Alice'); // Seed from account with balance on this network
+
+ const collection = await helper.nft.mintCollection(donor, {
+ name: 'test mintToSubstrate',
+ description: 'EVMHelpers',
+ tokenPrefix: 'ap',
+ tokenPropertyPermissions: [
+ {
+ key: 'url',
+ permission: {
+ tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true,
+ },
+ },
+ ],
+ limits: { sponsorTransferTimeout: 0, sponsorApproveTimeout: 0 },
+ permissions: { mintMode: true },
+ });
+
+ await collection.addToAllowList(donor, {
+ Ethereum: helper.address.substrateToEth(donor.address),
+ });
+ await collection.addToAllowList(donor, { Substrate: donor.address });
+ await collection.addAdmin(donor, { Ethereum: ethSigner });
+ await collection.addAdmin(donor, {
+ Ethereum: helper.address.substrateToEth(donor.address),
+ });
+ await collection.addToAllowList(donor, { Ethereum: proxyContract });
+ await collection.addAdmin(donor, { Ethereum: proxyContract });
+ await collection.setTokenPropertyPermissions(donor, permissions);
+
+ return collection;
+}