-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test to validate HTTP headers
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
hardhat-tests/test/internal/hardhat-network/provider/http-headers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { assert } from "chai"; | ||
|
||
import { rpcQuantityToNumber } from "hardhat/internal/core/jsonrpc/types/base-types"; | ||
import { workaroundWindowsCiFailures } from "../../../utils/workaround-windows-ci-failures"; | ||
import { setCWD } from "../helpers/cwd"; | ||
import { FORKED_PROVIDERS } from "../helpers/providers"; | ||
|
||
describe("Forking with HTTP headers", function () { | ||
FORKED_PROVIDERS.forEach(({ rpcProvider, jsonRpcUrl, useProvider }) => { | ||
workaroundWindowsCiFailures.call(this, { isFork: true }); | ||
|
||
let url: string; | ||
let bearerToken: string; | ||
const bearerTokenSeparatorIndex = jsonRpcUrl.lastIndexOf("/"); | ||
if (bearerTokenSeparatorIndex !== -1) { | ||
url = jsonRpcUrl.substring(0, bearerTokenSeparatorIndex); | ||
bearerToken = jsonRpcUrl.substring(bearerTokenSeparatorIndex + 1); | ||
} | ||
|
||
describe(`Using ${rpcProvider}`, function () { | ||
setCWD(); | ||
|
||
this.beforeAll(function () { | ||
// Skip infura because it doesn't support an API key-based bearer token | ||
if (rpcProvider === "Infura") { | ||
this.skip(); | ||
} | ||
|
||
// Skip invalid URLs | ||
if (url === undefined || bearerToken === undefined) { | ||
this.skip(); | ||
} | ||
}); | ||
|
||
describe("With API key in HTTP headers", function () { | ||
useProvider({ | ||
forkConfig: { | ||
jsonRpcUrl: url, | ||
httpHeaders: { | ||
Authorization: `Bearer ${bearerToken}`, | ||
}, | ||
}, | ||
}); | ||
|
||
it("Complete JSON-RPC request", async function () { | ||
const blockNumber = await this.provider.send("eth_blockNumber"); | ||
const minBlockNumber = 10494745; // mainnet block number at 20.07.2020 | ||
assert.isAtLeast(rpcQuantityToNumber(blockNumber), minBlockNumber); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |