From 9b06b1a559214acf4b0737234f58ce883ac324ba Mon Sep 17 00:00:00 2001 From: viraj124 Date: Wed, 18 Sep 2024 16:43:19 +0530 Subject: [PATCH] fix: failing test --- .../integration-tests/tests/transfer_eth.ts | 18 ++++++++++-------- .../v3/FuelMessagePortalV3.sol | 4 +++- .../FuelERC20Gateway/FuelERC20GatewayV4.sol | 4 +++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/integration-tests/tests/transfer_eth.ts b/packages/integration-tests/tests/transfer_eth.ts index f26c7e5c..b9b92aab 100644 --- a/packages/integration-tests/tests/transfer_eth.ts +++ b/packages/integration-tests/tests/transfer_eth.ts @@ -448,10 +448,6 @@ describe('Transferring ETH', async function () { it('Rate limit parameters are updated when the initial duration is over', async () => { const deployer = await env.eth.deployer; - await env.eth.fuelMessagePortal - .connect(deployer) - .resetRateLimitAmount(parseEther(largeRateLimit)); - rateLimitDuration = await env.eth.fuelMessagePortal.rateLimitDuration(); // fast forward time @@ -460,15 +456,19 @@ describe('Transferring ETH', async function () { rateLimitDuration * 2n ); + const currentPeriodEndBeforeRelay = + await env.eth.fuelMessagePortal.currentPeriodEnd(); + + await env.eth.fuelMessagePortal + .connect(deployer) + .resetRateLimitAmount(parseEther(largeRateLimit)); + withdrawMessageProof = await generateWithdrawalMessageProof( fuelETHSender, ethereumETHReceiverAddress, NUM_ETH ); - const currentPeriodEndBeforeRelay = - await env.eth.fuelMessagePortal.currentPeriodEnd(); - await relayMessage(env, withdrawMessageProof); const currentPeriodEndAfterRelay = @@ -514,9 +514,11 @@ describe('Transferring ETH', async function () { ).to.be.true; expect( - currentWithdrawnAmountBeforeSettingLimit == + currentWithdrawnAmountBeforeSettingLimit > currentWithdrawnAmountAfterSettingLimit ).to.be.true; + + expect(currentWithdrawnAmountAfterSettingLimit == 0n).to.be.true; }); }); }); diff --git a/packages/solidity-contracts/contracts/fuelchain/FuelMessagePortal/v3/FuelMessagePortalV3.sol b/packages/solidity-contracts/contracts/fuelchain/FuelMessagePortal/v3/FuelMessagePortalV3.sol index ecbeea2f..03991f2e 100644 --- a/packages/solidity-contracts/contracts/fuelchain/FuelMessagePortal/v3/FuelMessagePortalV3.sol +++ b/packages/solidity-contracts/contracts/fuelchain/FuelMessagePortal/v3/FuelMessagePortalV3.sol @@ -80,7 +80,7 @@ contract FuelMessagePortalV3 is FuelMessagePortalV2 { * @param _amount The amount to reset the limit to. */ function resetRateLimitAmount(uint256 _amount) external onlyRole(SET_RATE_LIMITER_ROLE) { - // currentPeriodAmount is not updated to avoid a edge case scenario where extra amount can be withdrawn from the bridge when it sshoulddn't be + // currentPeriodAmount is not updated when duration hasn't passed to avoid a edge case scenario where extra amount can be withdrawn from the bridge when it sshoulddn't be // fo instance if rate limit is reduced & made less than the current withddrawn amount & increased to orginal before the duration ends then extra amount can be withdrawn // if rate limit is reduced is reduced & made less then the current withdrawn amount then the withdraw operation from the bridge would revert until the limit is increasedd or the duration has passed // if period has expired then currentPeriodAmount is zero @@ -88,6 +88,8 @@ contract FuelMessagePortalV3 is FuelMessagePortalV2 { unchecked { currentPeriodEnd = block.timestamp + rateLimitDuration; } + + currentPeriodAmount = 0; } limitAmount = _amount; diff --git a/packages/solidity-contracts/contracts/messaging/gateway/FuelERC20Gateway/FuelERC20GatewayV4.sol b/packages/solidity-contracts/contracts/messaging/gateway/FuelERC20Gateway/FuelERC20GatewayV4.sol index 55e2efac..71729317 100644 --- a/packages/solidity-contracts/contracts/messaging/gateway/FuelERC20Gateway/FuelERC20GatewayV4.sol +++ b/packages/solidity-contracts/contracts/messaging/gateway/FuelERC20Gateway/FuelERC20GatewayV4.sol @@ -154,7 +154,7 @@ contract FuelERC20GatewayV4 is * @param _rateLimitDuration The new rate limit duration. */ function resetRateLimitAmount(address _token, uint256 _amount, uint256 _rateLimitDuration) external onlyRole(SET_RATE_LIMITER_ROLE) { - // currentPeriodAmount is not updated to avoid a edge case scenario where extra amount can be withdrawn from the bridge when it sshoulddn't be + // currentPeriodAmount is not updated when duration hasn't passed to avoid a edge case scenario where extra amount can be withdrawn from the bridge when it sshoulddn't be // fo instance if rate limit is reduced & made less than the current withddrawn amount & increased to orginal before the duration ends then extra amount can be withdrawn // if rate limit is reduced is reduced & made less then the current withdrawn amount then the withdraw operation from the bridge would revert until the limit is increasedd or the duration has passed // avoid multiple SLOADS @@ -168,6 +168,8 @@ contract FuelERC20GatewayV4 is unchecked { currentPeriodEnd[_token] = block.timestamp + _rateLimitDuration; } + + currentPeriodAmount[_token] = 0; } limitAmount[_token] = _amount;