|
| 1 | +import type { EthereumProvider } from "../../../../src/types/providers.js"; |
| 2 | +import type { NetworkConfig } from "@ignored/hardhat-vnext/types/config"; |
| 3 | + |
| 4 | +import assert from "node:assert/strict"; |
| 5 | +import { describe, it } from "node:test"; |
| 6 | + |
| 7 | +import { HttpProvider } from "../../../../src/internal/builtin-plugins/network-manager/http-provider.js"; |
| 8 | +import { NetworkConnectionImplementation } from "../../../../src/internal/builtin-plugins/network-manager/network-connection.js"; |
| 9 | + |
| 10 | +describe("NetworkConnectionImplementation", () => { |
| 11 | + const localhostNetworkConfig: NetworkConfig = { |
| 12 | + type: "http", |
| 13 | + chainId: undefined, |
| 14 | + chainType: undefined, |
| 15 | + from: undefined, |
| 16 | + gas: "auto", |
| 17 | + gasMultiplier: 1, |
| 18 | + gasPrice: "auto", |
| 19 | + url: "http://localhost:8545", |
| 20 | + timeout: 20_000, |
| 21 | + httpHeaders: {}, |
| 22 | + }; |
| 23 | + |
| 24 | + describe("NetworkConnectionImplementation.create", () => { |
| 25 | + it("should create a new network connection", async () => { |
| 26 | + let expectedProvider: EthereumProvider | undefined; |
| 27 | + |
| 28 | + const createProvider = async (): Promise<EthereumProvider> => { |
| 29 | + expectedProvider = await HttpProvider.create({ |
| 30 | + url: localhostNetworkConfig.url, |
| 31 | + networkName: "localhost", |
| 32 | + extraHeaders: localhostNetworkConfig.httpHeaders, |
| 33 | + timeout: localhostNetworkConfig.timeout, |
| 34 | + }); |
| 35 | + |
| 36 | + return expectedProvider; |
| 37 | + }; |
| 38 | + |
| 39 | + const closeConnection = async () => {}; |
| 40 | + |
| 41 | + const networkConnection = await NetworkConnectionImplementation.create( |
| 42 | + 1, |
| 43 | + "localhost", |
| 44 | + "unknown", |
| 45 | + localhostNetworkConfig, |
| 46 | + closeConnection, |
| 47 | + createProvider, |
| 48 | + ); |
| 49 | + |
| 50 | + assert.equal(networkConnection.id, 1); |
| 51 | + assert.equal(networkConnection.networkName, "localhost"); |
| 52 | + assert.equal(networkConnection.chainType, "unknown"); |
| 53 | + assert.deepEqual(networkConnection.networkConfig, localhostNetworkConfig); |
| 54 | + assert.deepEqual(networkConnection.provider, expectedProvider); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments