From a2412b704f849f1cec028c90a5e212b14d0317b3 Mon Sep 17 00:00:00 2001 From: Azat Serikov Date: Wed, 6 Mar 2024 18:22:14 +0500 Subject: [PATCH] test(lido): getDepositableEther --- .../WithdrawalQueue__MockForLidoMisc.sol | 5 +++ test/0.4.24/lido/lido.misc.test.ts | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/test/0.4.24/contracts/WithdrawalQueue__MockForLidoMisc.sol b/test/0.4.24/contracts/WithdrawalQueue__MockForLidoMisc.sol index 7acec5d7f..1eb0277ef 100644 --- a/test/0.4.24/contracts/WithdrawalQueue__MockForLidoMisc.sol +++ b/test/0.4.24/contracts/WithdrawalQueue__MockForLidoMisc.sol @@ -4,10 +4,15 @@ pragma solidity 0.4.24; contract WithdrawalQueue__MockForLidoMisc { bool public isBunkerModeActive; + uint256 public unfinalizedStETH; // test helpers function mock__bunkerMode(bool active) external { isBunkerModeActive = active; } + + function mock__unfinalizedStETH(uint256 amount) external { + unfinalizedStETH = amount; + } } diff --git a/test/0.4.24/lido/lido.misc.test.ts b/test/0.4.24/lido/lido.misc.test.ts index 668f8322a..3b4918e68 100644 --- a/test/0.4.24/lido/lido.misc.test.ts +++ b/test/0.4.24/lido/lido.misc.test.ts @@ -223,4 +223,41 @@ describe("Lido:misc", () => { expect(await lido.getFeeDistribution()).to.deep.equal([treasuryFee, insuranceFee, modulesFee]); }); }); + + context("getDepositableEther", () => { + it("Returns the amount of ether eligible for deposits", async () => { + await lido.resume(); + + const bufferedEtherBefore = await lido.getBufferedEther(); + + // top up buffer + const deposit = ether("10.0"); + await lido.submit(ZeroAddress, { value: deposit }); + + expect(await lido.getDepositableEther()).to.equal(bufferedEtherBefore + deposit); + }); + + it("Returns 0 if reserved by the buffered ether is fully reserved for withdrawals", async () => { + await lido.resume(); + + const bufferedEther = await lido.getBufferedEther(); + + // reserve all buffered ether for withdrawals + await withdrawalQueue.mock__unfinalizedStETH(bufferedEther); + + expect(await lido.getDepositableEther()).to.equal(0); + }); + + it("Returns the difference if the buffered ether is partially reserved", async () => { + await lido.resume(); + + const bufferedEther = await lido.getBufferedEther(); + + // reserve half of buffered ether for withdrawals + const reservedForWithdrawals = bufferedEther / 2n; + await withdrawalQueue.mock__unfinalizedStETH(reservedForWithdrawals); + + expect(await lido.getDepositableEther()).to.equal(bufferedEther - reservedForWithdrawals); + }); + }); });