Skip to content

Commit 63a820d

Browse files
committed
feat: expose hre to the hardhat console's context
1 parent 1fde8fe commit 63a820d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

v-next/hardhat/src/internal/builtin-plugins/console/task-action.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const consoleAction: NewTaskActionFunction<ConsoleActionArguments> = async (
3838
resolve(replServer);
3939
});
4040

41+
// Add the Hardhat Runtime Environment to the REPL context
42+
replServer.context.hre = _hre;
43+
4144
// Set up the REPL history file if the historyPath has been set
4245
if (historyPath !== undefined) {
4346
replServer.setupHistory(historyPath, (err: Error | null) => {

v-next/hardhat/test/internal/builtin-plugins/console/task-action.ts

+14
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ describe("console/task-action", function () {
112112
});
113113
});
114114

115+
describe("context", function () {
116+
it("should expose the Hardhat Runtime Environment", async function () {
117+
const replServer = await consoleAction(
118+
{
119+
commands: ["console.log(hre);", ".exit"],
120+
history: "",
121+
options,
122+
},
123+
hre,
124+
);
125+
assert.equal(replServer.lastError, undefined);
126+
});
127+
});
128+
115129
describe("history", function () {
116130
let cacheDir: string;
117131
let history: string;

0 commit comments

Comments
 (0)