From 568f574986262017ad30d868efe345c0e9332999 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier <gabriel.fournier@iex.ec> Date: Wed, 29 May 2024 09:57:33 +0200 Subject: [PATCH] make poco less complicated --- contracts/mocks/IexecPocoMock.sol | 31 ++----------------------------- test/VoucherHub.test.ts | 10 ++-------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/contracts/mocks/IexecPocoMock.sol b/contracts/mocks/IexecPocoMock.sol index a6ce89b..0ca6cc5 100644 --- a/contracts/mocks/IexecPocoMock.sol +++ b/contracts/mocks/IexecPocoMock.sol @@ -13,14 +13,8 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; */ contract IexecPocoMock is ERC20 { using Math for uint256; - using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder; - using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder; - using IexecLibOrders_v5 for IexecLibOrders_v5.WorkerpoolOrder; - using IexecLibOrders_v5 for IexecLibOrders_v5.RequestOrder; bool public shouldRevertOnSponsorMatchOrders = false; bool public shouldRevertOnSponsorMatchOrdersBoost = false; - bytes32 public EIP712DOMAIN_SEPARATOR = "EIP712DOMAIN_SEPARATOR"; - mapping(bytes32 => uint256) public m_consumed; constructor() ERC20("Staked RLC", "SRLC") { _mint(msg.sender, 1000000); @@ -35,10 +29,6 @@ contract IexecPocoMock is ERC20 { if (shouldRevertOnSponsorMatchOrders) { revert("IexecPocoMock: Failed to sponsorMatchOrders"); } - bytes32 requestOrderTypedDataHash = _toTypedDataHash(requestOrder.hash()); - bytes32 appOrderTypedDataHash = _toTypedDataHash(appOrder.hash()); - bytes32 workerpoolOrderTypedDataHash = _toTypedDataHash(workerpoolOrder.hash()); - bytes32 datasetOrderTypedDataHash = _toTypedDataHash(datasetOrder.hash()); uint256 volume = computeDealVolume(appOrder, datasetOrder, workerpoolOrder, requestOrder); uint256 dealPrice = (appOrder.appprice + @@ -58,7 +48,6 @@ contract IexecPocoMock is ERC20 { revert("IexecPocoMock: Failed to sponsorMatchOrdersBoost"); } uint256 volume = computeDealVolume(appOrder, datasetOrder, workerpoolOrder, requestOrder); - uint256 dealPrice = (appOrder.appprice + datasetOrder.datasetprice + workerpoolOrder.workerpoolprice) * volume; @@ -79,26 +68,10 @@ contract IexecPocoMock is ERC20 { IexecLibOrders_v5.WorkerpoolOrder calldata workerpoolOrder, IexecLibOrders_v5.RequestOrder calldata requestOrder ) public view returns (uint256) { - bytes32 requestOrderTypedDataHash = _toTypedDataHash(requestOrder.hash()); - bytes32 appOrderTypedDataHash = _toTypedDataHash(appOrder.hash()); - bytes32 workerpoolOrderTypedDataHash = _toTypedDataHash(workerpoolOrder.hash()); - bytes32 datasetOrderTypedDataHash = _toTypedDataHash(datasetOrder.hash()); return Math.min( - Math.min( - Math.min( - appOrder.volume - m_consumed[appOrderTypedDataHash], - datasetOrder.dataset != address(0) - ? datasetOrder.volume - m_consumed[datasetOrderTypedDataHash] - : type(uint256).max - ), - workerpoolOrder.volume - m_consumed[workerpoolOrderTypedDataHash] - ), - requestOrder.volume - m_consumed[requestOrderTypedDataHash] + datasetOrder.dataset != address(0) ? datasetOrder.volume : type(uint256).max, + requestOrder.volume ); } - - function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) { - return MessageHashUtils.toTypedDataHash(EIP712DOMAIN_SEPARATOR, structHash); - } } diff --git a/test/VoucherHub.test.ts b/test/VoucherHub.test.ts index c3bc564..0e9387d 100644 --- a/test/VoucherHub.test.ts +++ b/test/VoucherHub.test.ts @@ -42,14 +42,8 @@ describe('VoucherHub', function () { anyone, ] = await ethers.getSigners(); const beacon = await voucherUtils.deployBeaconAndImplementation(admin.address); - const iexecLibOrders = await ethers.getContractFactory('IexecLibOrders_v5'); - const iexecLibOrdersInstance = await iexecLibOrders.deploy(); - const iexecLibOrdersInstanceAddress = await iexecLibOrdersInstance.getAddress(); - - iexecPocoInstance = await new IexecPocoMock__factory({ - ['@iexec/poco/contracts/libs/IexecLibOrders_v5.sol:IexecLibOrders_v5']: - iexecLibOrdersInstanceAddress, - }) + + iexecPocoInstance = await new IexecPocoMock__factory() .connect(admin) .deploy() .then((x) => x.waitForDeployment());