Skip to content

Commit

Permalink
test: port some tests back to Lido contact tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vp4242 committed Jan 15, 2025
1 parent 212161e commit 43482eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 85 deletions.
47 changes: 45 additions & 2 deletions test/0.4.24/lido/lido.accounting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -34,6 +34,7 @@ describe("Lido:accounting", () => {
let lido: Lido;
let acl: ACL;
let postTokenRebaseReceiver: IPostTokenRebaseReceiver;
let locator: LidoLocator;

Check failure on line 37 in test/0.4.24/lido/lido.accounting.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript

Cannot find name 'LidoLocator'.

let elRewardsVault: LidoExecutionLayerRewardsVault__MockForLidoAccounting;
let withdrawalVault: WithdrawalVault__MockForLidoAccounting;
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
83 changes: 0 additions & 83 deletions test/0.8.9/accounting.handleOracleReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 43482eb

Please sign in to comment.