From a68cb1a9e100a879f5abd9b72451c8f3cf4979b1 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 16 Jan 2023 14:09:48 +0000 Subject: [PATCH] fix: bencmark for fee calculation Fixed bugs caused by changes in the signatures of interface functions and data structures --- --- a/tests/src/benchmarks/mintFee/benchmark.ts +++ b/tests/src/benchmarks/mintFee/benchmark.ts @@ -293,6 +293,8 @@ const evmContract = await helper.ethNativeContract.collection( helper.ethAddress.fromCollectionId(collection.collectionId), 'nft', + undefined, + true, ); const subTokenId = await evmContract.methods.nextTokenId().call(); @@ -351,9 +353,7 @@ encodedCall = await evmContract.methods .setProperties( subTokenId, - PROPERTIES.slice(0, setup.propertiesNumber).map((p) => { - return {field_0: p.key, field_1: p.value}; - }), + PROPERTIES.slice(0, setup.propertiesNumber), ) .encodeABI(); @@ -394,9 +394,7 @@ .mintToSubstrateBulkProperty( helper.ethAddress.fromCollectionId(collection.collectionId), susbstrateReceiver.addressRaw, - PROPERTIES.slice(0, setup.propertiesNumber).map((p) => { - return {field_0: p.key, field_1: p.value}; - }), + PROPERTIES.slice(0, setup.propertiesNumber), ) .send({from: ethSigner, gas: 25_000_000}); }, --- a/tests/src/benchmarks/mintFee/proxyContract.sol +++ b/tests/src/benchmarks/mintFee/proxyContract.sol @@ -3,21 +3,44 @@ import {CollectionHelpers} from "../../eth/api/CollectionHelpers.sol"; import {ContractHelpers} from "../../eth/api/ContractHelpers.sol"; import {UniqueRefungibleToken} from "../../eth/api/UniqueRefungibleToken.sol"; -import {UniqueRefungible, Collection, EthCrossAccount as RftCrossAccountId, Tuple20 as RftProperties} from "../../eth/api/UniqueRefungible.sol"; -import {UniqueNFT, EthCrossAccount as NftCrossAccountId, Tuple21 as NftProperty, TokenProperties} from "../../eth/api/UniqueNFT.sol"; +import {UniqueRefungible, Collection, CrossAddress as RftCrossAccountId, Property as RftProperty} from "../../eth/api/UniqueRefungible.sol"; +import {UniqueNFT, CrossAddress as NftCrossAccountId, Property as NftProperty} from "../../eth/api/UniqueNFT.sol"; struct Property { string key; bytes value; } +interface SoftDeprecatedMethods { + /// @notice Set token property value. + /// @dev Throws error if `msg.sender` has no permission to edit the property. + /// @param tokenId ID of the token. + /// @param key Property key. + /// @param value Property value. + /// @dev EVM selector for this function is: 0x1752d67b, + /// or in textual repr: setProperty(uint256,string,bytes) + function setProperty( + uint256 tokenId, + string memory key, + bytes memory value + ) external; +} + +interface BenchUniqueRefungible is UniqueRefungible, SoftDeprecatedMethods {} +interface BenchUniqueNFT is UniqueNFT, SoftDeprecatedMethods {} + + + contract ProxyMint { bytes32 constant REFUNGIBLE_COLLECTION_TYPE = keccak256(bytes("ReFungible")); bytes32 constant NONFUNGIBLE_COLLECTION_TYPE = keccak256(bytes("NFT")); modifier checkRestrictions(address _collection) { Collection commonContract = Collection(_collection); - require(commonContract.isOwnerOrAdmin(msg.sender), "Only collection admin/owner can call this method"); + require( + commonContract.isOwnerOrAdminCross(RftCrossAccountId(msg.sender, 0)), + "Only collection admin/owner can call this method" + ); _; } @@ -58,9 +81,9 @@ function mintToSubstrateWithProperty( address _collection, uint256 _substrateReceiver, - Property[] calldata properties + Property[] calldata _properties ) external checkRestrictions(_collection) { - uint256 propertiesLength = properties.length; + uint256 propertiesLength = _properties.length; require(propertiesLength > 0, "Properies is empty"); Collection commonContract = Collection(_collection); @@ -68,11 +91,12 @@ uint256 tokenId; if (collectionType == REFUNGIBLE_COLLECTION_TYPE) { - UniqueRefungible rftCollection = UniqueRefungible(_collection); + BenchUniqueRefungible rftCollection = BenchUniqueRefungible(_collection); tokenId = rftCollection.nextTokenId(); rftCollection.mint(address(this)); + for (uint256 i = 0; i < propertiesLength; ++i) { - rftCollection.setProperty(tokenId, properties[i].key, properties[i].value); + rftCollection.setProperty(tokenId, _properties[i].key, _properties[i].value); } rftCollection.transferFromCross( RftCrossAccountId(address(this), 0), @@ -80,10 +104,10 @@ tokenId ); } else if (collectionType == NONFUNGIBLE_COLLECTION_TYPE) { - UniqueNFT nftCollection = UniqueNFT(_collection); + BenchUniqueNFT nftCollection = BenchUniqueNFT(_collection); tokenId = nftCollection.mint(address(this)); for (uint256 i = 0; i < propertiesLength; ++i) { - nftCollection.setProperty(tokenId, properties[i].key, properties[i].value); + nftCollection.setProperty(tokenId, _properties[i].key, _properties[i].value); } nftCollection.transferFromCross( NftCrossAccountId(address(this), 0), -- gitstuff