-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the network hooks and NetworkConnection initialization
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
v-next/hardhat/test/internal/builtin-plugins/network-manager/network-connection.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,57 @@ | ||
import type { EthereumProvider } from "../../../../src/types/providers.js"; | ||
import type { NetworkConfig } from "@ignored/hardhat-vnext/types/config"; | ||
|
||
import assert from "node:assert/strict"; | ||
import { describe, it } from "node:test"; | ||
|
||
import { HttpProvider } from "../../../../src/internal/builtin-plugins/network-manager/http-provider.js"; | ||
import { NetworkConnectionImplementation } from "../../../../src/internal/builtin-plugins/network-manager/network-connection.js"; | ||
|
||
describe("NetworkConnectionImplementation", () => { | ||
const localhostNetworkConfig: NetworkConfig = { | ||
type: "http", | ||
chainId: undefined, | ||
chainType: undefined, | ||
from: undefined, | ||
gas: "auto", | ||
gasMultiplier: 1, | ||
gasPrice: "auto", | ||
url: "http://localhost:8545", | ||
timeout: 20_000, | ||
httpHeaders: {}, | ||
}; | ||
|
||
describe("NetworkConnectionImplementation.create", () => { | ||
it("should create a new network connection", async () => { | ||
let expectedProvider: EthereumProvider | undefined; | ||
|
||
const createProvider = async (): Promise<EthereumProvider> => { | ||
expectedProvider = await HttpProvider.create({ | ||
url: localhostNetworkConfig.url, | ||
networkName: "localhost", | ||
extraHeaders: localhostNetworkConfig.httpHeaders, | ||
timeout: localhostNetworkConfig.timeout, | ||
}); | ||
|
||
return expectedProvider; | ||
}; | ||
|
||
const closeConnection = async () => {}; | ||
|
||
const networkConnection = await NetworkConnectionImplementation.create( | ||
1, | ||
"localhost", | ||
"unknown", | ||
localhostNetworkConfig, | ||
closeConnection, | ||
createProvider, | ||
); | ||
|
||
assert.equal(networkConnection.id, 1); | ||
assert.equal(networkConnection.networkName, "localhost"); | ||
assert.equal(networkConnection.chainType, "unknown"); | ||
assert.deepEqual(networkConnection.networkConfig, localhostNetworkConfig); | ||
assert.deepEqual(networkConnection.provider, expectedProvider); | ||
}); | ||
}); | ||
}); |
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