Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update LidoLocator with wstEth contract address #164

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7693ed0
chore: update contributing guide again
tamtamchik Aug 21, 2024
92880a6
chore: 0.4.24 grooming
tamtamchik Aug 21, 2024
b988d27
chore: 0.4.24 grooming continues
tamtamchik Aug 21, 2024
c2864a1
chore: 0.4.24 grooming continues more
tamtamchik Aug 21, 2024
3531d28
chore: 0.4.24 grooming lido and nor tests
tamtamchik Aug 22, 2024
7169cad
chore: 0.4.24 grooming done
tamtamchik Aug 22, 2024
f58b34d
chore: 0.6.12 grooming done
tamtamchik Aug 22, 2024
f9dc2be
chore: 0.8.4 grooming done
tamtamchik Aug 22, 2024
cf52ab9
chore: cleanup some deploy params
tamtamchik Aug 22, 2024
97ba06d
chore: 0.8.9 grooming contracts
tamtamchik Aug 22, 2024
9b9b8ed
chore: 0.8.9 grooming done
tamtamchik Aug 23, 2024
46a4f5b
chore: grooming sol files and deploys
tamtamchik Aug 23, 2024
d475cbe
fix: ci errors
tamtamchik Aug 23, 2024
4b84f0f
ci: bump hh version
tamtamchik Aug 23, 2024
0d9df71
chore: add auto-lint for test contracts
tamtamchik Aug 23, 2024
81e68be
Merge pull request #159 from lidofinance/feat/mock-harness
tamtamchik Aug 26, 2024
2fc9848
lint: run prettier
tamtamchik Aug 26, 2024
46993d5
feat: add wstEth to LidoLocator
tamtamchik Aug 26, 2024
f85bafb
fix: test and scratch deploy
tamtamchik Aug 26, 2024
c406de1
fix: locator deployment for tests
tamtamchik Aug 26, 2024
2778b98
ci: try to invalidate cache
tamtamchik Aug 26, 2024
c426a86
ci: try to invalidate cache - reverted
tamtamchik Aug 26, 2024
66dcdc5
Merge branch 'repovation' into feat/locator-update
tamtamchik Aug 26, 2024
d462d8a
docs: update interface docs
tamtamchik Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
hardhat-node:
image: feofanov/hardhat-node:2.22.8
image: feofanov/hardhat-node:2.22.9
ports:
- 8545:8545
env:
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
foundry
contracts/**/*.sol

.gitignore
.prettierignore

eslint.config.mjs

package-lock.json
13 changes: 12 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
"singleQuote": false,
"printWidth": 120,
"tabWidth": 2,
"quoteProps": "consistent"
"quoteProps": "consistent",
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"tabWidth": 4,
"useTabs": false
}
}
]
}
103 changes: 57 additions & 46 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,99 +128,93 @@ This repository features a Hardhat-Foundry dual setup:
- Hardhat gives much more flexibility when writing complex tests;
- The Foundry's fuzzing capabilities enable better coverage of edge cases.

#### Tracing
#### Hardhat

Hardhat tests are all located in `/tests` at the root of the project.
Each subdirectory name corresponds to the version of the contract being tested, mirroring the `/contracts` directory
structure. Integration, regression, and other non-unit tests are placed into corresponding subdirectories,
e.g. `/tests/integration/`, ` /tests/regression`, etc.

##### Tracing

`hardhat-tracer` is used to trace contract calls and state changes during tests.
During Hardhat tests, the `hardhat-tracer` is used to trace contract calls and state changes.
Full-scale transaction tracing is disabled by default because it can significantly slow down the tests.

> [!NOTE]
> Tracing is ONLY supported in Hardhat unit tests and integration tests using Hardhat mainnet fork (see below).

To enable tracing, you need to wrap the code you want to trace with the `Tracer.enable()` and `Tracer.disable()`
functions:
functions and run the tests with the appropriate command postfix, e.g. `yarn test:trace`.

```typescript
import { Tracer } from 'test/suite';
import { Tracer } from "test/suite";

describe('MyContract', () => {
it('should do something', async () => {
describe("MyContract", () => {
it("should do something", async () => {
Tracer.enable();
// code to trace
Tracer.disable();
});
});
```

Then run the tests with the following commands:
##### Unit tests

```bash
yarn test:trace # Run all tests with trace logging (calls only)
yarn test:fulltrace # Run all tests with full trace logging (calls and storage ops)
yarn test:integration:trace # Run all integration tests with trace logging
yarn test:integration:fulltrace # Run all integration tests with full trace logging
```
Unit tests are located in `/tests` at the root of the project.
These tests are designed to verify the behavior of individual contracts and functions.
Naming conventions follow utilizes the `*.test.ts` postfix, e.g. `myContract.test.ts`.

> [!NOTE]
> Tracing is not supported in Foundry tests and integration tests other than Hardhat mainnet fork tests.
If you require mocks or wrappers for external contracts, please place them in the appropriate subdirectories, such as
`/tests/0.4.24/contracts` and adhere to the naming conventions:

#### Hardhat
- Use the `Mock` postfix for self-established contracts that simulate the behavior of the target contract. For example,
`MyContract_Mock.sol` or `MyContract_MockForAnotherContract.sol`.
- Use the `Harness` postfix for a wrapper that exposes private functions of a contract and may include test-specific
actions. For example, `MyContract_Wrapper.sol` or `MyContract_WrapperForAnotherContract.sol`.

Hardhat tests are all located in `/tests` at the root of the project.
Each subdirectory name corresponds to the version of the contract being tested, mirroring the `/contracts` directory
structure. Integration, regression, and other non-unit tests are placed into corresponding subdirectories,
e.g. `/tests/integration/`, ` /tests/regression`, etc.
You can run unit tests in multiple ways:

```bash
yarn test # Run all tests in parallel
yarn test:sequential # Run all tests sequentially
yarn test:trace # Run all tests with trace logging (see Tracing section)
yarn test:trace # Run all tests with trace logging (calls only)
yarn test:fulltrace # Run all tests with full trace logging (calls and storage ops)
yarn test:watch # Run all tests in watch mode
```

#### Foundry

Foundry's Solidity tests are used only for fuzzing library contracts or functions performing complex calculations
or byte juggling. Solidity tests are located under ` / tests` and in the appropriate subdirectories. Naming conventions
follow the Foundry's [documentation](https://book.getfoundry.sh/tutorials/best-practices#general-test-guidance):

- for tests, postfix `.t.sol` is used (e.g., `MyContract.t.sol`)
- for scripts, postfix `.s.sol` is used (e.g., `MyScript.s.sol`)
- for helpers, postfix `.h.sol` is used (e.g., `MyHelper.h.sol`).

Following the convention of distinguishing Hardhat test files from Foundry-related files is essential to ensure the
proper execution of Hardhat tests.

```bash
yarn test:foundry # Run all Foundry tests
```

#### Integration tests
##### Integration tests

Integration tests are located in `/tests/integration` at the root of the project.
These tests are used to verify the interaction between different contracts and their behavior in a real-world scenario.
Naming conventions follow the `*.int.ts` postfix, e.g. `myScenario.int.ts`.

You can run integration tests in multiple ways, but for all of them, you need to have a `.env` file in the root of
the project (you can use `.env.example` as a template).

##### Hardhat Mainnet Fork
###### Hardhat Mainnet Fork

This is the most common way to run integration tests. It uses the Hardhat mainnet fork to simulate the mainnet
environment. Requires `HARDHAT_FORKING_URL` and `HARDHAT_FORKING_BLOCK_NUMBER` (optional) to be set in the `.env` file
along with `MAINNET_*` env variables (see `.env.example`).
along with some `MAINNET_*` env variables (see `.env.example`).

```bash
yarn test:integration # Run all integration tests
yarn test:integration:trace # Run all integration tests with trace logging (see Tracing section)
yarn test:integration # Run all integration tests
yarn test:integration:trace # Run all integration tests with trace logging (calls only)
yarn test:integration:fulltrace # Run all integration tests with full trace logging (calls and storage ops)
```

##### Local setup
###### Local setup

This method is used to run integration tests against a local scratch deployment (
see [scratch-deploy.md](./docs/scratch-deploy.md)).
Requires `LOCAL_*` env variables to be set and a local deployment to be running on port `8555`.
Requires a local deployment to be running on port `8555` and `deployed-local.json` with the deployed addresses
(automatically generated during the scratch deployment).

```bash
yarn test:integration:local
```

##### Any fork setup
###### Any fork setup

This method is used to run integration tests against any fork. Requires `MAINNET_*` env variables to be set in the
`.env` file and a fork to be running on port `8545`.
Expand All @@ -229,6 +223,23 @@ This method is used to run integration tests against any fork. Requires `MAINNET
yarn test:integration:fork
```

#### Foundry tests

Foundry's Solidity tests are used only for fuzzing library contracts or functions performing complex calculations
or byte juggling. Solidity tests are located under ` / tests` and in the appropriate subdirectories. Naming conventions
follow the Foundry's [documentation](https://book.getfoundry.sh/tutorials/best-practices#general-test-guidance):

- for tests, postfix `.t.sol` is used (e.g., `MyContract.t.sol`)
- for scripts, postfix `.s.sol` is used (e.g., `MyScript.s.sol`)
- for helpers, postfix `.h.sol` is used (e.g., `MyHelper.h.sol`).

Following the convention of distinguishing Hardhat test files from Foundry-related files is essential to ensure the
proper execution of Hardhat tests.

```bash
yarn test:foundry # Run all Foundry tests
```

#### Coverage

The project uses the `hardhat-coverage` plugin to generate coverage reports.
Expand Down
10 changes: 7 additions & 3 deletions contracts/0.8.9/LidoLocator.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;

// solhint-disable immutable-vars-naming

import {ILidoLocator} from "../common/interfaces/ILidoLocator.sol";

/**
Expand All @@ -28,6 +29,7 @@ contract LidoLocator is ILidoLocator {
address withdrawalQueue;
address withdrawalVault;
address oracleDaemonConfig;
address wstEth;
}

error ZeroAddress();
Expand All @@ -46,6 +48,7 @@ contract LidoLocator is ILidoLocator {
address public immutable withdrawalQueue;
address public immutable withdrawalVault;
address public immutable oracleDaemonConfig;
address public immutable wstEth;

/**
* @notice declare service locations
Expand All @@ -67,9 +70,10 @@ contract LidoLocator is ILidoLocator {
withdrawalQueue = _assertNonZero(_config.withdrawalQueue);
withdrawalVault = _assertNonZero(_config.withdrawalVault);
oracleDaemonConfig = _assertNonZero(_config.oracleDaemonConfig);
wstEth = _assertNonZero(_config.wstEth);
}

function coreComponents() external view returns(
function coreComponents() external view returns (
address,
address,
address,
Expand All @@ -87,7 +91,7 @@ contract LidoLocator is ILidoLocator {
);
}

function oracleReportComponentsForLido() external view returns(
function oracleReportComponentsForLido() external view returns (
address,
address,
address,
Expand Down
41 changes: 24 additions & 17 deletions contracts/common/interfaces/ILidoLocator.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

// See contracts/COMPILERS.md
// solhint-disable-next-line
pragma solidity >=0.4.24 <0.9.0;

interface ILidoLocator {
function accountingOracle() external view returns(address);
function depositSecurityModule() external view returns(address);
function elRewardsVault() external view returns(address);
function legacyOracle() external view returns(address);
function lido() external view returns(address);
function oracleReportSanityChecker() external view returns(address);
function burner() external view returns(address);
function stakingRouter() external view returns(address);
function treasury() external view returns(address);
function validatorsExitBusOracle() external view returns(address);
function withdrawalQueue() external view returns(address);
function withdrawalVault() external view returns(address);
function postTokenRebaseReceiver() external view returns(address);
function oracleDaemonConfig() external view returns(address);
function coreComponents() external view returns(

function accountingOracle() external view returns (address);
function depositSecurityModule() external view returns (address);
function elRewardsVault() external view returns (address);
function legacyOracle() external view returns (address);
function lido() external view returns (address);
function oracleReportSanityChecker() external view returns (address);
function burner() external view returns (address);
function stakingRouter() external view returns (address);
function treasury() external view returns (address);
function validatorsExitBusOracle() external view returns (address);
function withdrawalQueue() external view returns (address);
function withdrawalVault() external view returns (address);
function postTokenRebaseReceiver() external view returns (address);
function oracleDaemonConfig() external view returns (address);
function wstEth() external view returns (address);

/// @dev Returns a batch of core components addresses at once.
/// It's just a more gas-efficient way of calling several public getters at once.
function coreComponents() external view returns (
address elRewardsVault,
address oracleReportSanityChecker,
address stakingRouter,
address treasury,
address withdrawalQueue,
address withdrawalVault
);
function oracleReportComponentsForLido() external view returns(

/// @dev Returns a batch of addresses that is used specifically during oracle report handling in the Lido contract.
/// It's just a more gas-efficient way of calling several public getters at once.
function oracleReportComponentsForLido() external view returns (
address accountingOracle,
address elRewardsVault,
address oracleReportSanityChecker,
Expand Down
2 changes: 1 addition & 1 deletion lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function getDeployTxParams(deployer: string) {
maxFeePerGas: ethers.parseUnits(String(GAS_MAX_FEE), "gwei"),
};
} else {
throw new Error("Must specify gas ENV vars: \"GAS_PRIORITY_FEE\" and \"GAS_MAX_FEE\" in gwei (like just \"3\")");
throw new Error('Must specify gas ENV vars: "GAS_PRIORITY_FEE" and "GAS_MAX_FEE" in gwei (like just "3")');
}
}

Expand Down
10 changes: 7 additions & 3 deletions lib/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ const parseLogEntry = (entry: Log, interfaces: Interface[]): LogDescription | nu
return null;
};

export function findEventsWithInterfaces(receipt: ContractTransactionReceipt, eventName: string, interfaces: Interface[]): LogDescription[] {
export function findEventsWithInterfaces(
receipt: ContractTransactionReceipt,
eventName: string,
interfaces: Interface[],
): LogDescription[] {
const events: LogDescription[] = [];
const notParsedLogs: Log[] = [];

receipt.logs.forEach(entry => {
receipt.logs.forEach((entry) => {
const logDescription = parseLogEntry(entry, interfaces);
if (logDescription) {
events.push(logDescription);
Expand All @@ -59,7 +63,7 @@ export function findEventsWithInterfaces(receipt: ContractTransactionReceipt, ev
// log.warning("The following logs could not be parsed:", notParsedLogs);
}

return events.filter(e => e.name === eventName);
return events.filter((e) => e.name === eventName);
}

export function findEvents(receipt: ContractTransactionReceipt, eventName: string) {
Expand Down
5 changes: 3 additions & 2 deletions lib/protocol/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getSigner = async (signer: Signer, balance = ether("100"), signers: Protoc

export const getProtocolContext = async (): Promise<ProtocolContext> => {
const { contracts, signers } = await discover();
const interfaces = Object.values(contracts).map(contract => contract.interface);
const interfaces = Object.values(contracts).map((contract) => contract.interface);

// By default, all flags are "on"
const flags = {
Expand All @@ -30,7 +30,8 @@ export const getProtocolContext = async (): Promise<ProtocolContext> => {
interfaces,
flags,
getSigner: async (signer: Signer, balance?: bigint) => getSigner(signer, balance, signers),
getEvents: (receipt: ContractTransactionReceipt, eventName: string) => findEventsWithInterfaces(receipt, eventName, interfaces),
getEvents: (receipt: ContractTransactionReceipt, eventName: string) =>
findEventsWithInterfaces(receipt, eventName, interfaces),
} as ProtocolContext;

await provision(context);
Expand Down
Loading
Loading