Skip to content

Commit

Permalink
feat: allow config vars in http network url
Browse files Browse the repository at this point in the history
  • Loading branch information
schaable committed Dec 18, 2024
1 parent b48796e commit ffdb527
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function resolveUserConfig(
gas: resolveGasConfig(networkConfig.gas),
gasMultiplier: networkConfig.gasMultiplier ?? 1,
gasPrice: resolveGasConfig(networkConfig.gasPrice),
url: networkConfig.url,
url: resolveConfigurationVariable(networkConfig.url),
timeout: networkConfig.timeout ?? 20_000,
httpHeaders: networkConfig.httpHeaders ?? {},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class NetworkManagerImplementation implements NetworkManager {
}

return HttpProvider.create({
url: resolvedNetworkConfig.url,
url: await resolvedNetworkConfig.url.getUrl(),
networkName: resolvedNetworkName,
extraHeaders: resolvedNetworkConfig.httpHeaders,
timeout: resolvedNetworkConfig.timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare module "../../../../types/config.js" {
gasPrice?: GasUserConfig;

// HTTP network specific
url: string;
url: SensitiveString;
httpHeaders?: Record<string, string>;
timeout?: number;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ declare module "../../../../types/config.js" {
gasPrice: GasConfig;

// HTTP network specific
url: string;
url: ResolvedConfigurationVariable;
httpHeaders: Record<string, string>;
timeout: number;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const httpNetworkUserConfigSchema = z.object({
gasPrice: z.optional(gasUserConfigSchema),

// HTTP network specific
url: z.string().url(), // TODO: this should be a sensitiveUrlSchema
url: sensitiveUrlSchema,
httpHeaders: z.optional(z.record(z.string())),
timeout: z.optional(z.number()),
});
Expand Down Expand Up @@ -177,7 +177,7 @@ const httpNetworkConfigSchema = z.object({
gasPrice: gasConfigSchema,

// HTTP network specific
url: sensitiveUrlSchema,
url: resolvedConfigurationVariableSchema,
httpHeaders: z.record(z.string()),
timeout: z.number(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ describe("network-manager/hook-handlers/config", () => {
assertValidationErrors(validationErrors, [
{
path: ["networks", "localhost", "url"],
message: "Required",
message: "Expected a URL or a Configuration Variable",
},
]);
});
Expand All @@ -487,7 +487,7 @@ describe("network-manager/hook-handlers/config", () => {
assertValidationErrors(validationErrors, [
{
path: ["networks", "localhost", "url"],
message: "Invalid url",
message: "Expected a URL or a Configuration Variable",
},
]);
});
Expand Down Expand Up @@ -1202,7 +1202,7 @@ describe("network-manager/hook-handlers/config", () => {
nextUserConfig: HardhatUserConfig,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
-- Cast for simplicity as we won't test this */
) => nextUserConfig as HardhatConfig;
) => nextUserConfig as unknown as HardhatConfig;

const resolvedConfig = await resolveUserConfig(
extendedConfig,
Expand All @@ -1222,7 +1222,7 @@ describe("network-manager/hook-handlers/config", () => {
gasMultiplier: 1,
gasPrice: "auto",
accounts: "remote",
url: "http://localhost:8545",
url: new FixedValueConfigurationVariable("http://localhost:8545"),
timeout: 20_000,
httpHeaders: {},
},
Expand Down Expand Up @@ -1258,7 +1258,7 @@ describe("network-manager/hook-handlers/config", () => {
nextUserConfig: HardhatUserConfig,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
-- Cast for simplicity as we won't test this */
) => nextUserConfig as HardhatConfig;
) => nextUserConfig as unknown as HardhatConfig;

const resolvedConfig = await resolveUserConfig(
userConfig,
Expand All @@ -1268,6 +1268,7 @@ describe("network-manager/hook-handlers/config", () => {

assert.equal(resolvedConfig.defaultChainType, "generic");
assert.equal(resolvedConfig.defaultNetwork, "myNetwork");
assert.equal(resolvedConfig.networks.myNetwork.type, "http");
assert.deepEqual(resolvedConfig.networks, {
myNetwork: {
type: "http",
Expand All @@ -1282,7 +1283,7 @@ describe("network-manager/hook-handlers/config", () => {
"0x000006d4548a3ac17d72b372ae1e416bf65b8ead",
),
],
url: "http://node.myNetwork.com",
url: new FixedValueConfigurationVariable("http://node.myNetwork.com"),
timeout: 10_000,
httpHeaders: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -1322,7 +1323,7 @@ describe("network-manager/hook-handlers/config", () => {
nextUserConfig: HardhatUserConfig,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
-- Cast for simplicity as we won't test this */
) => nextUserConfig as HardhatConfig;
) => nextUserConfig as unknown as HardhatConfig;

const resolvedConfig = await resolveUserConfig(
userConfig,
Expand Down Expand Up @@ -1353,7 +1354,9 @@ describe("network-manager/hook-handlers/config", () => {
"0x000006d4548a3ac17d72b372ae1e416bf65b8ddd",
),
],
url: "http://node.myNetwork.com",
url: new FixedValueConfigurationVariable(
"http://node.myNetwork.com",
),
timeout: 10_000,
httpHeaders: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -1390,7 +1393,7 @@ describe("network-manager/hook-handlers/config", () => {
nextUserConfig: HardhatUserConfig,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
-- Cast for simplicity as we won't test this */
) => nextUserConfig as HardhatConfig;
) => nextUserConfig as unknown as HardhatConfig;

const resolvedConfig = await resolveUserConfig(
userConfig,
Expand All @@ -1414,7 +1417,9 @@ describe("network-manager/hook-handlers/config", () => {
path: "m/44'/60'/0'/0",
passphrase: "passphrase",
},
url: "http://node.myNetwork.com",
url: new FixedValueConfigurationVariable(
"http://node.myNetwork.com",
),
timeout: 10_000,
httpHeaders: {
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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";
import { FixedValueConfigurationVariable } from "../../../../src/internal/core/configuration-variables.js";

describe("NetworkConnectionImplementation", () => {
const localhostNetworkConfig: NetworkConfig = {
Expand All @@ -17,7 +18,7 @@ describe("NetworkConnectionImplementation", () => {
gasMultiplier: 1,
gasPrice: "auto",
accounts: [],
url: "http://localhost:8545",
url: new FixedValueConfigurationVariable("http://localhost:8545"),
timeout: 20_000,
httpHeaders: {},
};
Expand All @@ -28,7 +29,7 @@ describe("NetworkConnectionImplementation", () => {

const createProvider = async (): Promise<EthereumProvider> => {
expectedProvider = await HttpProvider.create({
url: localhostNetworkConfig.url,
url: await localhostNetworkConfig.url.getUrl(),
networkName: "localhost",
extraHeaders: localhostNetworkConfig.httpHeaders,
timeout: localhostNetworkConfig.timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { expectTypeOf } from "expect-type";
import { createHardhatRuntimeEnvironment } from "../../../../src/hre.js";
import { NetworkManagerImplementation } from "../../../../src/internal/builtin-plugins/network-manager/network-manager.js";
import { validateNetworkConfig } from "../../../../src/internal/builtin-plugins/network-manager/type-validation.js";
import { FixedValueConfigurationVariable } from "../../../../src/internal/core/configuration-variables.js";

describe("NetworkManagerImplementation", () => {
let hre: HardhatRuntimeEnvironment;
Expand All @@ -31,7 +32,7 @@ describe("NetworkManagerImplementation", () => {
gasMultiplier: 1,
gasPrice: "auto",
accounts: [],
url: "http://localhost:8545",
url: new FixedValueConfigurationVariable("http://localhost:8545"),
timeout: 20_000,
httpHeaders: {},
},
Expand All @@ -44,7 +45,7 @@ describe("NetworkManagerImplementation", () => {
gasMultiplier: 1,
gasPrice: "auto",
accounts: [],
url: "http://node.customNetwork.com",
url: new FixedValueConfigurationVariable("http://node.customNetwork.com"),
timeout: 20_000,
httpHeaders: {},
},
Expand All @@ -57,7 +58,7 @@ describe("NetworkManagerImplementation", () => {
gasMultiplier: 1,
gasPrice: "auto",
accounts: [],
url: "http://node.myNetwork.com",
url: new FixedValueConfigurationVariable("http://node.myNetwork.com"),
timeout: 20_000,
httpHeaders: {},
},
Expand Down

0 comments on commit ffdb527

Please sign in to comment.