UNPKG

@foundry-rs/hardhat-anvil

Version:

Hardhat plugin for managing Anvil

31 lines 1.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useEnvironment = void 0; const plugins_testing_1 = require("hardhat/plugins-testing"); const path_1 = __importDefault(require("path")); const net_1 = __importDefault(require("net")); function useEnvironment(fixtureProjectName, networkName = "localhost") { beforeEach("Loading hardhat environment", async function () { process.chdir(path_1.default.join(__dirname, "fixture-projects", fixtureProjectName)); process.env.HARDHAT_NETWORK = networkName; this.env = require("hardhat"); this.freePort = await getPortFree(); }); afterEach("Resetting hardhat", function () { (0, plugins_testing_1.resetHardhatContext)(); }); } exports.useEnvironment = useEnvironment; async function getPortFree() { return new Promise((res) => { const srv = net_1.default.createServer(); srv.listen(0, () => { const port = srv.address().port; srv.close((_err) => res(port)); }); }); } //# sourceMappingURL=helpers.js.map