From 17070f7a1545e73c1890c0e8b87e1dced74c9edd Mon Sep 17 00:00:00 2001 From: Andres Adjimann Date: Sat, 30 Sep 2023 10:17:21 -0300 Subject: [PATCH] test: remove bundle, use the right encoder --- packages/marketplace/test/utils/assets.ts | 72 ++++------------------- 1 file changed, 11 insertions(+), 61 deletions(-) diff --git a/packages/marketplace/test/utils/assets.ts b/packages/marketplace/test/utils/assets.ts index 370b4ef89a..66d912f268 100644 --- a/packages/marketplace/test/utils/assets.ts +++ b/packages/marketplace/test/utils/assets.ts @@ -2,14 +2,7 @@ // "20 eth" == AssetETH(20), "11 Sand" == AssetERC20(SandTokenAddress, 11) // some NFT" == AssetERC721(nftContractAddress, tokenId), etc // SEE: LibAsset.sol -import { - AbiCoder, - BytesLike, - Contract, - keccak256, - Numeric, - solidityPackedKeccak256, -} from 'ethers'; +import {AbiCoder, BytesLike, Contract, keccak256, Numeric} from 'ethers'; export enum AssetClassType { INVALID_ASSET_CLASS = '0x0', @@ -81,66 +74,23 @@ export const AssetERC1155 = async ( value: value, }); -export const AssetBundle = async ( - erc20: {token: Contract; value: Numeric}[], - erc721: { - token: Contract; - tokenId: Numeric; - }[], - erc1155: { - token: Contract; - tokenId: Numeric; - value: Numeric; - }[] -): Promise => { - const erc20Details = []; - for (const x of erc20) { - erc20Details.push([await x.token.getAddress(), x.value]); - } - const erc721Details = []; - for (const x of erc721) { - erc721Details.push([ - await x.token.getAddress(), - x.tokenId, - // TODO: Test value !=1 - 1, - ]); - } - const erc1155Details = []; - for (const x of erc1155) { - erc1155Details.push([await x.token.getAddress(), x.tokenId, x.value]); - } - return { - assetType: { - assetClass: BUNDLE_ASSET_CLASS, - data: AbiCoder.defaultAbiCoder().encode( - [ - 'tuple(address, uint256)[]', - 'tuple(address, uint256, uint256)[]', - 'tuple(address, uint256, uint256)[]', - ], - [erc20Details, erc721Details, erc1155Details] - ), - }, - // TODO: It make sense tho have multipler bundles >1 ???? - value: 1, - }; -}; - export function hashAssetType(a: AssetType) { if (a.assetClass === AssetClassType.INVALID_ASSET_CLASS) { throw new Error('Invalid assetClass' + a.assetClass); } - // There is aproblem with solidityPackedKeccak256 and byte4 => a.assetClass + '0'.repeat(56) - return solidityPackedKeccak256( - ['bytes32', 'uint256', 'bytes32'], - [ASSET_TYPE_TYPEHASH, a.assetClass, keccak256(a.data)] + return keccak256( + AbiCoder.defaultAbiCoder().encode( + ['bytes32', 'uint256', 'bytes32'], + [ASSET_TYPE_TYPEHASH, a.assetClass, keccak256(a.data)] + ) ); } export function hashAsset(a: Asset) { - return solidityPackedKeccak256( - ['bytes32', 'bytes32', 'uint256'], - [ASSET_TYPEHASH, hashAssetType(a.assetType), a.value] + return keccak256( + AbiCoder.defaultAbiCoder().encode( + ['bytes32', 'bytes32', 'uint256'], + [ASSET_TYPEHASH, hashAssetType(a.assetType), a.value] + ) ); }