diff --git a/.changeset/chatty-clouds-melt.md b/.changeset/chatty-clouds-melt.md new file mode 100644 index 0000000000000..2d037bf75fed0 --- /dev/null +++ b/.changeset/chatty-clouds-melt.md @@ -0,0 +1,5 @@ +--- +"@eth-optimism/hardhat-ovm": minor +--- + +allow overriding the ethers polling interval diff --git a/packages/hardhat-ovm/package.json b/packages/hardhat-ovm/package.json index 9bbf74984b1c2..8793ce405d448 100644 --- a/packages/hardhat-ovm/package.json +++ b/packages/hardhat-ovm/package.json @@ -17,8 +17,11 @@ "dependencies": { "node-fetch": "^2.6.1" }, - "devDependencies": { - "@types/mocha": "^8.2.2", + "peerDependencies": { + "ethers": "^5.1.4", "hardhat": "^2.1.2" + }, + "devDependencies": { + "@types/mocha": "^8.2.2" } } diff --git a/packages/hardhat-ovm/src/index.ts b/packages/hardhat-ovm/src/index.ts index 274ec7bc68daf..477427847bd5c 100644 --- a/packages/hardhat-ovm/src/index.ts +++ b/packages/hardhat-ovm/src/index.ts @@ -2,6 +2,7 @@ import * as fs from 'fs' import * as path from 'path' import fetch from 'node-fetch' +import { ethers } from 'ethers' import { subtask, extendEnvironment } from 'hardhat/config' import { getCompilersDir } from 'hardhat/internal/util/global-dir' import { Artifacts } from 'hardhat/internal/artifacts' @@ -23,6 +24,10 @@ const OPTIMISM_SOLC_BIN_URL = // default to 0.6.X instead? const DEFAULT_OVM_SOLC_VERSION = '0.7.6' +// Poll the node every 50ms, to override ethers.js's default 4000ms causing OVM +// tests to be slow. +const OVM_POLLING_INTERVAL = 50 + /** * Find or generate an OVM soljson.js compiler file and return the path of this file. * We pass the path to this file into hardhat. @@ -200,5 +205,26 @@ extendEnvironment((hre) => { ;(hre as any).config.typechain.outDir += '-ovm' } } + + // if ethers is present, override the polling interval to not wait the full + // duration in tests + if ((hre as any).ethers) { + ;(hre as any).ethers.getSigners = async () => { + let signers = await (hre as any).ethers.getSigners() + signers = signers.map((s: any) => { + s._signer.provider.pollingInterval = + hre.network.config.interval || OVM_POLLING_INTERVAL + return s + }) + return signers + } + + const provider = new ethers.providers.JsonRpcProvider( + (hre as any).ethers.provider.url + ) + provider.pollingInterval = + hre.network.config.interval || OVM_POLLING_INTERVAL + ;(hre as any).ethers.provider = provider + } } }) diff --git a/packages/hardhat-ovm/src/type-extensions.ts b/packages/hardhat-ovm/src/type-extensions.ts index 2d6758ca6adce..dfe8ef6beef91 100644 --- a/packages/hardhat-ovm/src/type-extensions.ts +++ b/packages/hardhat-ovm/src/type-extensions.ts @@ -26,11 +26,13 @@ declare module 'hardhat/types/config' { interface HardhatNetworkConfig { ovm: boolean ignoreRxList: string[] + interval?: number } interface HttpNetworkConfig { ovm: boolean ignoreRxList: string[] + interval?: number } }