Skip to content

Commit

Permalink
Merge commit '2d11786ebc1f06165c501fa8e9fecef053e12ab9' into feat/wit…
Browse files Browse the repository at this point in the history
…hdrawal-credentials
  • Loading branch information
mkurayan committed Jan 30, 2025
2 parents 811fdf8 + 2d11786 commit 6cdc711
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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
HARDHAT_FORKING_URL=
HARDHAT_FORKING_URL=https://eth.drpc.org

# https://docs.lido.fi/deployed-contracts
MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mainnet environment, allowing you to run integration tests with trace logging.
> [!NOTE]
> 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).
> `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment.
```bash
# Run all integration tests
Expand Down
47 changes: 4 additions & 43 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import * as process from "node:process";

import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
Expand All @@ -12,41 +11,15 @@ import "hardhat-tracer";
import "hardhat-watcher";
import "hardhat-ignore-warnings";
import "hardhat-contract-sizer";
import { globSync } from "glob";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { HardhatUserConfig, subtask } from "hardhat/config";
import { HardhatUserConfig } from "hardhat/config";

import { mochaRootHooks } from "test/hooks";

import "./tasks";

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

const HARDHAT_FORKING_URL = process.env.HARDHAT_FORKING_URL || "";

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

/* Determines the forking configuration for Hardhat */
function getHardhatForkingConfig() {
if (INTEGRATION_WITH_SCRATCH_DEPLOY === "on" || !HARDHAT_FORKING_URL) {
return undefined;
}
return { url: HARDHAT_FORKING_URL };
}
import { getHardhatForkingConfig, loadAccounts } from "./hardhat.helpers";

function loadAccounts(networkName: string) {
// TODO: this plaintext accounts.json private keys management is a subject
// of rework to a solution with the keys stored encrypted
if (!existsSync(ACCOUNTS_PATH)) {
return [];
}
const content = JSON.parse(readFileSync(ACCOUNTS_PATH, "utf-8"));
if (!content.eth) {
return [];
}
return content.eth[networkName] || [];
}
const RPC_URL: string = process.env.RPC_URL || "";

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
Expand Down Expand Up @@ -185,16 +158,4 @@ const config: HardhatUserConfig = {
},
};

// a workaround for having an additional source directory for compilation
// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => {
const paths = await runSuper();

const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol");
// Don't need to compile test, helper and script files that are not part of the contracts for Hardhat.
const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x));

return [...paths, ...otherPaths];
});

export default config;
32 changes: 32 additions & 0 deletions hardhat.helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { existsSync, readFileSync } from "node:fs";

/* Determines the forking configuration for Hardhat */
export function getHardhatForkingConfig() {
const forkingUrl = process.env.HARDHAT_FORKING_URL || "";

if (!forkingUrl) {
// Scratch deploy, need to disable CSM
process.env.INTEGRATION_ON_SCRATCH = "on";
process.env.INTEGRATION_WITH_CSM = "off";
return undefined;
}

return { url: forkingUrl };
}

// TODO: this plaintext accounts.json private keys management is a subject
// of rework to a solution with the keys stored encrypted
export function loadAccounts(networkName: string) {
const accountsPath = "./accounts.json";

if (!existsSync(accountsPath)) {
return [];
}

const content = JSON.parse(readFileSync(accountsPath, "utf-8"));
if (!content.eth) {
return [];
}

return content.eth[networkName] || [];
}
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./verify-contracts";
export * from "./extract-abis";
export * from "./solidity-get-source";
18 changes: 18 additions & 0 deletions tasks/solidity-get-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import path from "node:path";

import { globSync } from "glob";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { subtask } from "hardhat/config";

// a workaround for having an additional source directory for compilation
// see, https://github.com/NomicFoundation/hardhat/issues/776#issuecomment-1713584386

subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, hre, runSuper) => {
const paths = await runSuper();

const otherDirectoryGlob = path.join(hre.config.paths.root, "test", "**", "*.sol");
// Don't need to compile test, helper and script files that are not part of the contracts for Hardhat.
const otherPaths = globSync(otherDirectoryGlob).filter((x) => !/\.([ths]\.sol)$/.test(x));

return [...paths, ...otherPaths];
});

0 comments on commit 6cdc711

Please sign in to comment.