Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: parse cli time option correctly #1731

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/chains/ethereum/options/src/chain-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ export type ChainConfig = {
*/
readonly time: {
type: Date;
rawType: Date | string;
rawType: Date | string | number;
legacy: {
/**
* @deprecated Use chain.time instead
*/
time: Date | string;
};
cliType: string;
};

/**
Expand Down Expand Up @@ -175,17 +176,21 @@ export const ChainOptions: Definitions<ChainConfig> = {
cliType: "number"
},
time: {
normalize: rawInput => {
if (typeof rawInput === "string") {
return new Date(rawInput);
} else {
return rawInput;
}
},
normalize: rawInput => new Date(rawInput),
cliDescription: "Date that the first block should start.",
legacyName: "time",
cliAliases: ["t", "time"],
cliType: "number"
cliType: "string",
cliCoerce: (input: string) => {
// try parsing the input as a number, if it works use the number
// otherwise pass the string along
const asNum = (input as any) / 1;
if (isNaN(asNum)) {
return input;
} else {
return asNum;
}
}
},
hardfork: {
normalize,
Expand Down