From 601ff2521d817894b4ac828eeed865f8715eac30 Mon Sep 17 00:00:00 2001 From: jtfirek Date: Thu, 3 Oct 2024 17:04:57 -0500 Subject: [PATCH] additional testing --- src/LiquidityPool.sol | 1 + src/WithdrawRequestNFT.sol | 4 ++++ test/WithdrawRequestNFT.t.sol | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/LiquidityPool.sol b/src/LiquidityPool.sol index 0962a64cf..2510caf22 100644 --- a/src/LiquidityPool.sol +++ b/src/LiquidityPool.sol @@ -423,6 +423,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL emit Rebase(getTotalPooledEther(), eETH.totalShares()); } + /// @notice pay protocol fees including 5% to treaury, 5% to node operator and ethfund bnft holders /// @param _protocolFees The amount of protocol fees to pay in ether function payProtocolFees(uint128 _protocolFees) external { diff --git a/src/WithdrawRequestNFT.sol b/src/WithdrawRequestNFT.sol index 887277d8d..403da1a75 100644 --- a/src/WithdrawRequestNFT.sol +++ b/src/WithdrawRequestNFT.sol @@ -154,6 +154,10 @@ contract WithdrawRequestNFT is ERC721Upgradeable, UUPSUpgradeable, OwnableUpgrad /// @param lastRequestId the id of the last request to finalize in this batch, will update `lastFinalizedRequestId` value function finalizeRequests(uint32 lastRequestId) external { if (!roleRegistry.hasRole(WITHDRAW_NFT_ADMIN_ROLE, msg.sender)) revert IncorrectRole(); + require(lastRequestId >= lastFinalizedRequestId, "Invalid lastRequestId submitted"); + + // No new requests have been finalized since the last oracle report + if (lastRequestId == lastFinalizedRequestId) { return; } uint256 totalAmount = uint256(calculateTotalPendingAmount(lastRequestId)); _finalizeRequests(lastRequestId, totalAmount); diff --git a/test/WithdrawRequestNFT.t.sol b/test/WithdrawRequestNFT.t.sol index 5ae5ba361..5ac847054 100644 --- a/test/WithdrawRequestNFT.t.sol +++ b/test/WithdrawRequestNFT.t.sol @@ -312,12 +312,23 @@ contract WithdrawRequestNFTTest is TestSetup { // Within `LP.requestWithdraw` // - `share` is calculated by `sharesForAmount` as (9 * 98) / 100 = 8.82 ---> (rounded down to) 8 + uint256 dustSharesBefore = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount(); + console.log("dustSharesBefore: ", dustSharesBefore); + + vm.prank(address(membershipManagerInstance)); + liquidityPoolInstance.rebase(2); _finalizeWithdrawalRequest(requestId); + uint256 dustSharesAfter = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount(); + console.log("dustSharesAfter: ", dustSharesAfter); vm.prank(bob); withdrawRequestNFTInstance.claimWithdraw(requestId, 1); + + uint256 dustSharesAfter2 = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount(); + console.log("dustSharesAfter2: ", dustSharesAfter2); + // Within `claimWithdraw`, // - `request.amountOfEEth` is 9 // - `amountForShares` is (8 * 100) / 98 = 8.16 ---> (rounded down to) 8 @@ -452,7 +463,19 @@ contract WithdrawRequestNFTTest is TestSetup { liquidityPoolInstance.rebase(50 ether); // finalize the requests in multiple batches + _finalizeWithdrawalRequest(5); + + uint256 dustShares1 = withdrawRequestNFTInstance.getAccumulatedDustEEthAmount(); + + // no new NFTs where finalized during this period + _finalizeWithdrawalRequest(5); + // dust should remain the same amount + assertEq(dustShares1, withdrawRequestNFTInstance.getAccumulatedDustEEthAmount()); + + vm.expectRevert("Invalid lastRequestId submitted"); + _finalizeWithdrawalRequest(4); + _finalizeWithdrawalRequest(11); _finalizeWithdrawalRequest(17); _finalizeWithdrawalRequest(23);