Skip to content

Commit

Permalink
Merge pull request #25 from lidofinance/test/lido
Browse files Browse the repository at this point in the history
Lido staking tests
  • Loading branch information
mymphe authored Feb 16, 2024
2 parents 8c4edb6 + 3981b62 commit 51c7fa9
Show file tree
Hide file tree
Showing 16 changed files with 746 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .vscode/snippets.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Place your lido-core workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": ["console.log('$1');", "$2"],
"description": "Log output to console",
},
"Create a context": {
"scope": "javascript,typescript",
"prefix": "ctx",
"body": ["context(\"$1\", () => {\n\t$2\n});"],
"description": "Create a context",
},
"Create a test": {
"scope": "javascript,typescript",
"prefix": "it",
"body": ["it(\"$1\", async () => {\n\t$2\n});"],
"description": "Create a test",
},
}
18 changes: 18 additions & 0 deletions lib/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bigintToHex } from "bigint-conversion";
import { ethers } from "hardhat";

import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";

import { getNetworkName } from "./client";

export async function impersonate(address: string, balance?: bigint): Promise<HardhatEthersSigner> {
const networkName = await getNetworkName();

await ethers.provider.send(`${networkName}_impersonateAccount`, [address]);

if (balance) {
await ethers.provider.send(`${networkName}_setBalance`, [address, "0x" + bigintToHex(balance)]);
}

return ethers.getSigner(address);
}
6 changes: 4 additions & 2 deletions lib/aragon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Kernel,
Kernel__factory,
Lido__factory,
LidoLocator,
} from "typechain-types";

import { dummyLocator } from "./dummy";
Expand Down Expand Up @@ -60,9 +61,10 @@ export async function addAragonApp({ dao, name, impl, rootAccount }: CreateAddAp
interface DeployLidoDaoArgs {
rootAccount: HardhatEthersSigner;
initialized: boolean;
locatorConfig?: Partial<LidoLocator.ConfigStruct>;
}

export async function deployLidoDao({ rootAccount, initialized }: DeployLidoDaoArgs) {
export async function deployLidoDao({ rootAccount, initialized, locatorConfig = {} }: DeployLidoDaoArgs) {
const { dao, acl } = await createAragonDao(rootAccount);

const impl = await new Lido__factory(rootAccount).deploy();
Expand All @@ -77,7 +79,7 @@ export async function deployLidoDao({ rootAccount, initialized }: DeployLidoDaoA
const lido = Lido__factory.connect(lidoProxyAddress, rootAccount);

if (initialized) {
const locator = await dummyLocator({ lido }, rootAccount);
const locator = await dummyLocator({ lido, ...locatorConfig }, rootAccount);
const eip712steth = await new EIP712StETH__factory(rootAccount).deploy(lido);
await lido.initialize(locator, eip712steth, { value: ether("1.0") });
}
Expand Down
15 changes: 15 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ethers } from "hardhat";

export async function getNetworkName(): Promise<string> {
let clientVersion = await ethers.provider.send("web3_clientVersion");

if (typeof clientVersion !== "string") {
throw new Error("Failed to retrieve client version!");
}

clientVersion = clientVersion.toLowerCase();
if (clientVersion.includes("hardhat")) return "hardhat";
if (clientVersion.includes("anvil")) return "anvil";

throw new Error("Unexpected client!");
}
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from "./dummy";
export * from "./event";
export * from "./aragon";
export * from "./dsm";
export * from "./account";
export * from "./client";
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@types/node": ">=16.0.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"bigint-conversion": "^2.4.3",
"chai": "^4.2.0",
"dotenv": "^16.3.1",
"eslint": "^8.48.0",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions test/0.4.24/contracts/StakingRouterMinimalApiForLido.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only
pragma solidity 0.4.24;


contract StakingRouterMinimalApiForLido {

function getWithdrawalCredentials() external view returns(bytes32) {
return 0x010000000000000000000000b9d7934878b5fb9610b3fe8a5e441e8fad7e293f; // Lido Withdrawal Creds
}

function getTotalFeeE4Precision() external view returns(uint16) {
return 1000; // 10%
}

function TOTAL_BASIS_POINTS() external view returns(uint256) {
return 10000; // 100%
}

function getStakingFeeAggregateDistributionE4Precision() external view returns(
uint16 treasuryFee,
uint16 modulesFee
) {
treasuryFee = 500;
modulesFee = 500;
}
}
17 changes: 17 additions & 0 deletions test/0.4.24/contracts/WithdrawalQueueMinimalApiForLido.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only
pragma solidity 0.4.24;


contract WithdrawalQueueMinimalApiForLido {
bool public isBunkerModeActive;
uint256 public unfinalizedStETH;

function _setBunkerMode(bool active) external {
isBunkerModeActive = active;
}

function _setUnfinalizedStETH(uint256 amount) external {
unfinalizedStETH = amount;
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 51c7fa9

Please sign in to comment.