Skip to content

Commit

Permalink
chore: updates non related to sdvt
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Oct 4, 2024
1 parent ede02e7 commit 60d6e23
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ LOCAL_WITHDRAWAL_VAULT_ADDRESS=

# RPC URL for a separate, non Hardhat Network node (Anvil, Infura, Alchemy, etc.)
MAINNET_RPC_URL=http://localhost:8545

# RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing (Infura, Alchemy, etc.)
# https://hardhat.org/hardhat-network/docs/guides/forking-other-networks#forking-other-networks
MAINNET_FORKING_URL=
HARDHAT_FORKING_URL=

# Chain ID for the network on Hardhat Network
HARDHAT_CHAIN_ID=

# https://docs.lido.fi/deployed-contracts
MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb
Expand Down
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ the [Lido Research Forum](https://research.lido.fi/).
- [Foundry](https://book.getfoundry.sh/) latest available version

> [!TIP]
> On macOS with Homebrew, it is recommended to install Node.js using [`n`](https://github.com/tj/n) or [ > `nvm`](https://github.com/nvm-sh/nvm) version managers.
> On macOS with Homebrew, it is recommended to install Node.js using [`n`](https://github.com/tj/n) or
> [ >`nvm`](https://github.com/nvm-sh/nvm) version managers.
>
> Example setup process using `n` package manager for zsh users:
>
> ```bash
Expand Down Expand Up @@ -325,8 +327,8 @@ This is the most common method for running integration tests. It uses an instanc
mainnet environment, allowing you to run integration tests with trace logging.
> [!NOTE]
> Ensure that `MAINNET_FORKING_URL` and other `MAINNET_*` environment variables are set in the `.env` file (refer to
> `.env.example` for guidance).
> Ensure that `HARDHAT_FORKING_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the
> `.env` file (refer to `.env.example` for guidance).
```bash
# Run all integration tests
Expand Down
18 changes: 12 additions & 6 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
declare namespace NodeJS {
export interface ProcessEnv {
/* RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing */
MAINNET_FORKING_URL?: string;
/* iternal logging verbosity (used in scratch deploy / integration tests) */
LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none"; // default: "info"

/* logging verbosity */
LOG_LEVEL?: "all" | "debug" | "info" | "warn" | "error" | "none";
/**
* Flags for changing the behavior of the Hardhat Network
*/

/* RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing */
HARDHAT_FORKING_URL?: string;
/* Chain ID for Hardhat Network forking, required for running tests on different networks */
HARDHAT_CHAIN_ID?: string;

/**
* Flags for changing the behavior of the integration tests
*/

/* if "on" the integration tests will deploy the contracts to the empty Hardhat Network node using scratch deploy */
INTEGRATION_SCRATCH_DEPLOY?: "on" | "off";
INTEGRATION_WITH_SCRATCH_DEPLOY?: "on" | "off"; // default: "off"
/* if "on" the integration tests will enable assertions and checks for the simple DVT module */
INTEGRATION_SIMPLE_DVT_MODULE?: "on" | "off";
INTEGRATION_WITH_SIMPLE_DVT_MODULE?: "on" | "off"; // default: "on"

/**
* Network configuration for the protocol discovery.
Expand Down
20 changes: 13 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ import { mochaRootHooks } from "test/hooks";
import "./tasks";

const RPC_URL: string = process.env.RPC_URL || "";
const MAINNET_FORKING_URL = process.env.MAINNET_FORKING_URL || "";
const INTEGRATION_SCRATCH_DEPLOY = process.env.INTEGRATION_SCRATCH_DEPLOY || "off";
const ACCOUNTS_PATH = "./accounts.json";

/**
* Determines the forking configuration for Hardhat.
* @returns The forking configuration object or undefined.
*/
const HARDHAT_CHAIN_ID_DEFAULT = 31337;
const HARDHAT_FORKING_URL = process.env.HARDHAT_FORKING_URL || "";
const HARDHAT_CHAIN_ID = process.env.HARDHAT_CHAIN_ID || HARDHAT_CHAIN_ID_DEFAULT;

const INTEGRATION_WITH_SCRATCH_DEPLOY = process.env.INTEGRATION_WITH_SCRATCH_DEPLOY || "off";

/* Determines the forking configuration for Hardhat */
function getHardhatForkingConfig() {
return INTEGRATION_SCRATCH_DEPLOY === "on" || !MAINNET_FORKING_URL ? undefined : { url: MAINNET_FORKING_URL };
if (INTEGRATION_WITH_SCRATCH_DEPLOY === "on" || !HARDHAT_FORKING_URL) {
return undefined;
}
return { url: HARDHAT_FORKING_URL };
}

function loadAccounts(networkName: string) {
Expand All @@ -51,6 +55,7 @@ const config: HardhatUserConfig = {
networks: {
"local": {
url: process.env.LOCAL_RPC_URL || RPC_URL,
chainId: HARDHAT_CHAIN_ID_DEFAULT,
},
"mainnet-fork": {
url: process.env.MAINNET_RPC_URL || RPC_URL,
Expand All @@ -69,6 +74,7 @@ const config: HardhatUserConfig = {
count: 30,
accountsBalance: "100000000000000000000000",
},
chainId: parseInt(HARDHAT_CHAIN_ID.toString()),
forking: getHardhatForkingConfig(),
},
"sepolia": {
Expand Down
4 changes: 2 additions & 2 deletions lib/protocol/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const getProtocolContext = async (): Promise<ProtocolContext> => {

// By default, all flags are "on"
const flags = {
isScratchDeploy: process.env.INTEGRATION_SCRATCH_DEPLOY === "on",
withSimpleDvtModule: process.env.INTEGRATION_SIMPLE_DVT_MODULE !== "off",
isScratchDeploy: process.env.INTEGRATION_WITH_SCRATCH_DEPLOY === "on",
withSimpleDvtModule: process.env.INTEGRATION_WITH_SIMPLE_DVT_MODULE !== "off",
} as ProtocolContextFlags;

log.debug("Protocol context flags", {
Expand Down
20 changes: 17 additions & 3 deletions lib/state-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type DeploymentState = {
[key: string]: any;
};

export const AppNames = {
export const TemplateAppNames = {
// Lido apps
LIDO: "lido",
ORACLE: "oracle",
Expand All @@ -32,6 +32,7 @@ export enum Sk {
appLido = "app:lido",
appOracle = `app:oracle`,
appNodeOperatorsRegistry = "app:node-operators-registry",
appSimpleDvt = "app:simple-dvt",
aragonAcl = "aragon-acl",
aragonEvmScriptRegistry = "aragon-evm-script-registry",
aragonApmRegistry = "aragon-apm-registry",
Expand All @@ -57,6 +58,7 @@ export enum Sk {
lidoTemplate = "lidoTemplate",
miniMeTokenFactory = "miniMeTokenFactory",
lidoTemplateCreateStdAppReposTx = "lidoTemplateCreateStdAppReposTx",
nodeOperatorsRegistry = "nodeOperatorsRegistry",
createAppReposTx = "createAppReposTx",
lidoTemplateNewDaoTx = "lidoTemplateNewDaoTx",
callsScript = "callsScript",
Expand Down Expand Up @@ -138,13 +140,25 @@ export function readNetworkState({
deployer?: string;
networkStateFile?: string;
} = {}) {
const networkName = hardhatNetwork.name;
const networkChainId = hardhatNetwork.config.chainId;

const fileName = networkStateFile
? resolve(NETWORK_STATE_FILE_DIR, networkStateFile)
: _getFileName(hardhatNetwork.name, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR);
: _getFileName(networkName, NETWORK_STATE_FILE_BASENAME, NETWORK_STATE_FILE_DIR);

const state = _readStateFile(fileName);

// Validate the deployer
if (deployer !== undefined && deployer != state.deployer) {
throw new Error(`The specified deployer ${deployer} does not match the one ${state.deployer} in the state file`);
throw new Error(`The specified deployer ${deployer} does not match the one ${state.deployer} in the state file!`);
}

// Validate the chainId
if (state[Sk.chainSpec].chainId && networkChainId !== parseInt(state[Sk.chainSpec].chainId)) {
throw new Error(
`The chainId: ${networkChainId} does not match the one (${state[Sk.chainSpec].chainId}) in the state file!`,
);
}

return state;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"test:integration": "hardhat test test/integration/**/*.ts --bail",
"test:integration:trace": "hardhat test test/integration/**/*.ts --trace --disabletracer --bail",
"test:integration:fulltrace": "hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail",
"test:integration:scratch": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --bail",
"test:integration:scratch:trace": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --trace --disabletracer --bail",
"test:integration:scratch:fulltrace": "INTEGRATION_SCRATCH_DEPLOY=on INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail",
"test:integration:fork:local": "INTEGRATION_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --network local --bail",
"test:integration:scratch": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --bail",
"test:integration:scratch:trace": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --trace --disabletracer --bail",
"test:integration:scratch:fulltrace": "INTEGRATION_WITH_SCRATCH_DEPLOY=on INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --fulltrace --disabletracer --bail",
"test:integration:fork:local": "INTEGRATION_WITH_SIMPLE_DVT_MODULE=off hardhat test test/integration/**/*.ts --network local --bail",
"test:integration:fork:mainnet": "hardhat test test/integration/**/*.ts --network mainnet-fork --bail",
"typecheck": "tsc --noEmit",
"prepare": "husky",
Expand Down

0 comments on commit 60d6e23

Please sign in to comment.