Skip to content

Commit

Permalink
Replace "unknown" with "generic" in ChainType
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Oct 26, 2024
1 parent 9aeef86 commit 7417384
Show file tree
Hide file tree
Showing 14 changed files with 5,585 additions and 4,084 deletions.
9,586 changes: 5,530 additions & 4,056 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions v-next/hardhat-viem/test/hook-handlers/network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
import type {
GenericChainType,
NetworkConnection,
} from "@ignored/hardhat-vnext/types/network";

import assert from "node:assert/strict";
import { before, describe, it } from "node:test";
Expand All @@ -10,7 +13,7 @@ import HardhatViem from "../../src/index.js";

describe("hook-handlers/network", () => {
describe("newConnection", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

before(async () => {
const hre = await createHardhatRuntimeEnvironment({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function resolveUserConfig(

return {
...resolvedConfig,
defaultChainType: resolvedConfig.defaultChainType ?? "unknown",
defaultChainType: resolvedConfig.defaultChainType ?? "generic",
defaultNetwork: resolvedConfig.defaultNetwork ?? "hardhat",
networks: resolvedNetworks,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const HD_ACCOUNT_PASSPHRASE_MSG = `${ACCOUNTS_ERROR} the "passphrase" property o
const HD_ACCOUNT_BALANCE_MSG = `${ACCOUNTS_ERROR} the "balance" property of the HD account must be a string`;

const chainTypeSchema = unionType(
[z.literal("l1"), z.literal("optimism"), z.literal("unknown")],
"Expected 'l1', 'optimism', or 'unknown'",
[z.literal("l1"), z.literal("optimism"), z.literal("generic")],
"Expected 'l1', 'optimism', or 'generic'",
);

const userGasSchema = conditionalUnionType(
Expand Down
15 changes: 10 additions & 5 deletions v-next/hardhat/src/types/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import type { EthereumProvider } from "./providers.js";

/**
* Represents the possible chain types for the network. The options are:
* - `"unknown"`: Represents the most generic type of network.
* - `GenericNetowrkType`: Represents the most generic type of network.
* - `"l1"`: Represents Layer 1 networks like Ethereum.
* - `"optimism"`: Represents Layer 2 networks like Optimism.
*/
export type ChainType = "unknown" | "l1" | "optimism";
export type ChainType = GenericChainType | "l1" | "optimism";

/**
* The most generic chanin type.
*/
export type GenericChainType = "generic";

/**
* Determines the default chain type to use when no chain type is specified.
* The default chain type is `"unknown"` by default. You can customize the
* The default chain type is GenericNetowrkType by default. You can customize the
* default chain type by adding a `defaultChainType` property to the
* `ChainTypeConfig` interface with a valid `ChainType` value.
* For example:
Expand All @@ -28,8 +33,8 @@ export type DefaultChainType = ChainTypeConfig extends {
}
? T extends ChainType
? T
: "unknown"
: "unknown";
: GenericChainType
: GenericChainType;

/* eslint-disable-next-line @typescript-eslint/no-empty-interface -- Empty
interface to allow the user to change the default chain type. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("network-manager/hook-handlers/config", () => {
describe("validateUserConfig", () => {
it("should pass if the config is valid", async () => {
const config: HardhatUserConfig = {
defaultChainType: "unknown",
defaultChainType: "generic",
defaultNetwork: "localhost",
networks: {
localhost: {
Expand Down Expand Up @@ -1094,7 +1094,7 @@ describe("network-manager/hook-handlers/config", () => {
const userConfig: HardhatUserConfig = {
// To change the defaultChainType, we need to augment the Hardhat types.
// Since this can't be done for a single test, we'll leave this untested.
defaultChainType: "unknown",
defaultChainType: "generic",
defaultNetwork: "myNetwork",
networks: {
myNetwork: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../../src/types/network.js";

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
Expand All @@ -12,7 +15,7 @@ import { createMockedNetworkHre } from "../../hooks-mock.js";
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - AutomaticSender", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

beforeEach(async () => {
const hre = await createMockedNetworkHre({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../../src/types/network.js";

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
Expand All @@ -12,7 +15,7 @@ import { createMockedNetworkHre } from "../../hooks-mock.js";
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - FixedSender", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

beforeEach(async () => {
const hre = await createMockedNetworkHre();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../src/types/network.js";

import { beforeEach, describe, it } from "node:test";

Expand All @@ -11,7 +14,7 @@ import { createMockedNetworkHre } from "../hooks-mock.js";
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - ChainIdValidator", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

describe("eth_chainId", () => {
beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../../src/types/network.js";

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
Expand All @@ -15,7 +18,7 @@ const GAS_MULTIPLIER = 1.337;
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - AutomaticGas", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

beforeEach(async () => {
const hre = await createMockedNetworkHre({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../../src/types/network.js";

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
Expand All @@ -12,7 +15,7 @@ import { createMockedNetworkHre } from "../../hooks-mock.js";
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - FixedGasPrice", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

const FIXED_GAS_PRICE = 1232n;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { NetworkConnection } from "../../../../../../../src/types/network.js";
import type {
GenericChainType,
NetworkConnection,
} from "../../../../../../../src/types/network.js";

import assert from "node:assert/strict";
import { beforeEach, describe, it } from "node:test";
Expand All @@ -14,7 +17,7 @@ const FIXED_GAS_LIMIT = 1231n;
// are correctly modified in the "onRequest" hook handler.
// These tests simulate a real scenario where the user calls "await connection.provider.request(jsonRpcRequest)".
describe("e2e - FixedGas", () => {
let connection: NetworkConnection<"unknown">;
let connection: NetworkConnection<GenericChainType>;

beforeEach(async () => {
const hre = await createMockedNetworkHre({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ describe("NetworkConnectionImplementation", () => {
const networkConnection = await NetworkConnectionImplementation.create(
1,
"localhost",
"unknown",
"generic",
localhostNetworkConfig,
closeConnection,
createProvider,
);

assert.equal(networkConnection.id, 1);
assert.equal(networkConnection.networkName, "localhost");
assert.equal(networkConnection.chainType, "unknown");
assert.equal(networkConnection.chainType, "generic");
assert.deepEqual(networkConnection.networkConfig, localhostNetworkConfig);
assert.deepEqual(networkConnection.provider, expectedProvider);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NetworkHooks } from "../../../../src/types/hooks.js";
import type { HardhatRuntimeEnvironment } from "../../../../src/types/hre.js";
import type {
GenericChainType,
NetworkConnection,
NetworkManager,
} from "../../../../src/types/network.js";
Expand Down Expand Up @@ -66,7 +67,7 @@ describe("NetworkManagerImplementation", () => {
hre = await createHardhatRuntimeEnvironment({});
networkManager = new NetworkManagerImplementation(
"localhost",
"unknown",
"generic",
networks,
hre.hooks,
);
Expand Down Expand Up @@ -198,7 +199,7 @@ describe("NetworkManagerImplementation", () => {
it("should create a NetworkConnection with the default chain type when no chain type is provided", async () => {
const networkConnection = await networkManager.connect("localhost");
expectTypeOf(networkConnection).toEqualTypeOf<
NetworkConnection<"unknown">
NetworkConnection<GenericChainType>
>();
});

Expand Down

0 comments on commit 7417384

Please sign in to comment.