Skip to content

Commit

Permalink
fix: failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
viraj124 committed Sep 18, 2024
1 parent d3f4e9d commit 9b06b1a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions packages/integration-tests/tests/transfer_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ 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
if (currentPeriodEnd < block.timestamp) {
unchecked {
currentPeriodEnd = block.timestamp + rateLimitDuration;
}

currentPeriodAmount = 0;
}

limitAmount = _amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -168,6 +168,8 @@ contract FuelERC20GatewayV4 is
unchecked {
currentPeriodEnd[_token] = block.timestamp + _rateLimitDuration;
}

currentPeriodAmount[_token] = 0;
}

limitAmount[_token] = _amount;
Expand Down

0 comments on commit 9b06b1a

Please sign in to comment.