diff --git a/test/0.4.24/lido/lido.accounting.test.ts b/test/0.4.24/lido/lido.accounting.test.ts index 344df58d2..dfd104f2d 100644 --- a/test/0.4.24/lido/lido.accounting.test.ts +++ b/test/0.4.24/lido/lido.accounting.test.ts @@ -23,7 +23,7 @@ import { WithdrawalVault__MockForLidoAccounting__factory, } from "typechain-types"; -import { ether, impersonate } from "lib"; +import { ether, getNextBlockTimestamp, impersonate } from "lib"; import { deployLidoDao } from "test/deploy"; @@ -34,6 +34,7 @@ describe("Lido:accounting", () => { let lido: Lido; let acl: ACL; let postTokenRebaseReceiver: IPostTokenRebaseReceiver; + let locator: LidoLocator; let elRewardsVault: LidoExecutionLayerRewardsVault__MockForLidoAccounting; let withdrawalVault: WithdrawalVault__MockForLidoAccounting; @@ -76,6 +77,7 @@ describe("Lido:accounting", () => { burner, }, })); + locator = LidoLocator__factory.connect(await lido.getLidoLocator(), deployer); await acl.createPermission(deployer, lido, await lido.RESUME_ROLE(), deployer); await acl.createPermission(deployer, lido, await lido.PAUSE_ROLE(), deployer); @@ -94,7 +96,6 @@ describe("Lido:accounting", () => { }); it("Updates beacon stats", async () => { - const locator = LidoLocator__factory.connect(await lido.getLidoLocator(), deployer); const accountingSigner = await impersonate(await locator.accounting(), ether("100.0")); lido = lido.connect(accountingSigner); await expect( @@ -141,6 +142,48 @@ describe("Lido:accounting", () => { ); }); + it("Updates buffered ether", async () => { + const initialBufferedEther = await lido.getBufferedEther(); + const ethToLock = 1n; + + // assert that the buffer has enough eth to lock for withdrawals + // should have some eth from the initial 0xdead holder + expect(initialBufferedEther).greaterThanOrEqual(ethToLock); + await withdrawalQueue.mock__prefinalizeReturn(ethToLock, 0n); + + const accountingSigner = await impersonate(await locator.accounting(), ether("100.0")); + lido = lido.connect(accountingSigner); + + await lido.collectRewardsAndProcessWithdrawals(...args({ etherToLockOnWithdrawalQueue: ethToLock })); + expect(await lido.getBufferedEther()).to.equal(initialBufferedEther - ethToLock); + }); + + it("Emits an `ETHDistributed` event", async () => { + const reportTimestamp = await getNextBlockTimestamp(); + const preClBalance = 0n; + const clBalance = 1n; + const withdrawals = 0n; + const elRewards = 0n; + const bufferedEther = await lido.getBufferedEther(); + + const totalFee = 1000; + const precisionPoints = 10n ** 20n; + await stakingRouter.mock__getStakingRewardsDistribution([], [], [], totalFee, precisionPoints); + + const accountingSigner = await impersonate(await locator.accounting(), ether("100.0")); + lido = lido.connect(accountingSigner); + await expect( + lido.collectRewardsAndProcessWithdrawals( + ...args({ + reportTimestamp, + reportClBalance: clBalance, + }), + ), + ) + .to.emit(lido, "ETHDistributed") + .withArgs(reportTimestamp, preClBalance, clBalance, withdrawals, elRewards, bufferedEther); + }); + type ArgsTuple = [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint]; interface Args { diff --git a/test/0.8.9/accounting.handleOracleReport.test.ts b/test/0.8.9/accounting.handleOracleReport.test.ts index f1685ad0e..4c002724b 100644 --- a/test/0.8.9/accounting.handleOracleReport.test.ts +++ b/test/0.8.9/accounting.handleOracleReport.test.ts @@ -170,95 +170,12 @@ describe("Accounting.sol:report", () => { .withArgs(isCover, await accounting.getAddress(), steth, sharesToBurn); }); - // TODO: This test could be moved to `Lido.sol` - // it("Withdraws ether from `ElRewardsVault` if EL rewards are greater than 0 as returned from `smoothenTokenRebase`", async () => { - it("ensures that `Lido.collectRewardsAndProcessWithdrawals` is called from `Accounting`", async () => { // `Mock__CollectRewardsAndProcessWithdrawals` event is only emitted on the mock to verify // that `Lido.collectRewardsAndProcessWithdrawals` was actually called await expect(accounting.handleOracleReport(report())).to.emit(lido, "Mock__CollectRewardsAndProcessWithdrawals"); }); - // it("Withdraws ether from `WithdrawalVault` if withdrawals are greater than 0 as returned from `smoothenTokenRebase`", async () => { - // const withdrawals = 1n; - // const elRewards = 0n; - // const simulatedSharesToBurn = 0n; - // const sharesToBurn = 0n; - - // await oracleReportSanityChecker.mock__smoothenTokenRebaseReturn( - // withdrawals, - // elRewards, - // simulatedSharesToBurn, - // sharesToBurn, - // ); - // const totalFee = 1000; - // const precisionPoints = 10n ** 20n; - // await stakingRouter.mock__getStakingRewardsDistribution([], [], [], totalFee, precisionPoints); - - // // `Mock__WithdrawalsWithdrawn` event is only emitted on the mock to verify - // // that `WithdrawalVault.withdrawWithdrawals` was actually called - // await expect(accounting.handleOracleReport(report())).to.emit(withdrawalVault, "Mock__WithdrawalsWithdrawn"); - // }); - - // it("Finalizes withdrawals if there is ether to lock on `WithdrawalQueue` as returned from `prefinalize`", async () => { - // const ethToLock = ether("10.0"); - // await withdrawalQueue.mock__prefinalizeReturn(ethToLock, 0n); - // // top up buffer via submit - // await lido.submit(ZeroAddress, { value: ethToLock }); - - // await expect( - // accounting.handleOracleReport( - // report({ - // withdrawalFinalizationBatches: [1n, 2n], - // }), - // ), - // ).to.emit(withdrawalQueue, "WithdrawalsFinalized"); - // }); - - // it("Updates buffered ether", async () => { - // const initialBufferedEther = await lido.getBufferedEther(); - // const ethToLock = 1n; - - // // assert that the buffer has enough eth to lock for withdrawals - // // should have some eth from the initial 0xdead holder - // expect(initialBufferedEther).greaterThanOrEqual(ethToLock); - // await withdrawalQueue.mock__prefinalizeReturn(ethToLock, 0n); - - // await expect( - // accounting.handleOracleReport( - // report({ - // withdrawalFinalizationBatches: [1n], - // }), - // ), - // ).to.not.be.reverted; - - // expect(await lido.getBufferedEther()).to.equal(initialBufferedEther - ethToLock); - // }); - - // it("Emits an `ETHDistributed` event", async () => { - // const reportTimestamp = await getNextBlockTimestamp(); - // const preClBalance = 0n; - // const clBalance = 1n; - // const withdrawals = 0n; - // const elRewards = 0n; - // const bufferedEther = await lido.getBufferedEther(); - - // const totalFee = 1000; - // const precisionPoints = 10n ** 20n; - // await stakingRouter.mock__getStakingRewardsDistribution([], [], [], totalFee, precisionPoints); - - // await expect( - // accounting.handleOracleReport( - // report({ - // timestamp: reportTimestamp, - // clBalance, - // }), - // ), - // ) - // .to.emit(lido, "ETHDistributed") - // .withArgs(reportTimestamp, preClBalance, clBalance, withdrawals, elRewards, bufferedEther); - // }); - it("Burns shares if there are shares to burn as returned from `smoothenTokenRebaseReturn`", async () => { const sharesRequestedToBurn = 1n; await oracleReportSanityChecker.mock__smoothenTokenRebaseReturn(0n, 0n, 0n, sharesRequestedToBurn);