Skip to content

Commit 2d6dfdf

Browse files
committed
feat(tests): add validation tests for input parsing and preset values
1 parent 47ecfa9 commit 2d6dfdf

7 files changed

Lines changed: 129 additions & 146 deletions

src/cli/build-command.test.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import type { BesuAllocAccount } from "../genesis/besu-genesis.service.ts";
55
import { ALGORITHM } from "../genesis/besu-genesis.service.ts";
66
import type { GeneratedNodeKey } from "../keys/node-key-factory.ts";
77
import type { BootstrapDependencies, CliOptions } from "./build-command.ts";
8-
import {
9-
__testing as buildCommandTesting,
10-
createCliCommand,
11-
runBootstrap,
12-
} from "./build-command.ts";
8+
import { createCliCommand, runBootstrap } from "./build-command.ts";
139
import type { OutputPayload, OutputType } from "./output.ts";
1410
import { outputResult as realOutputResult } from "./output.ts";
1511

@@ -346,23 +342,4 @@ describe("CLI command bootstrap", () => {
346342
`Consensus must be one of: ${Object.values(ALGORITHM).join(", ")}.`
347343
);
348344
});
349-
350-
test("parse helpers validate inputs", () => {
351-
expect(buildCommandTesting.parsePositiveInteger("5", "Label")).toBe(5);
352-
expect(buildCommandTesting.parseNonNegativeInteger("0", "Zero")).toBe(0);
353-
expect(buildCommandTesting.parsePositiveBigInt("123", "Big")).toBe("123");
354-
355-
expect(() =>
356-
buildCommandTesting.parsePositiveInteger("0", "Label")
357-
).toThrow("Label must be a positive integer.");
358-
expect(() =>
359-
buildCommandTesting.parseNonNegativeInteger("-1", "Zero")
360-
).toThrow("Zero must be a non-negative integer.");
361-
expect(() => buildCommandTesting.parsePositiveBigInt("-5", "Big")).toThrow(
362-
"Big must be a positive integer."
363-
);
364-
expect(() => buildCommandTesting.parsePositiveBigInt("not", "Big")).toThrow(
365-
"Big must be a positive integer."
366-
);
367-
});
368345
});

src/cli/build-command.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,3 @@ const createCliCommand = (
238238

239239
export type { BootstrapDependencies, CliOptions };
240240
export { createCliCommand, runBootstrap };
241-
export const __testing = {
242-
parsePositiveInteger,
243-
parseNonNegativeInteger,
244-
parsePositiveBigInt,
245-
};

src/cli/genesis-prompts.test.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
type BesuGenesisService,
99
} from "../genesis/besu-genesis.service.ts";
1010
import {
11-
__testing as genesisTesting,
1211
type HexAddress,
1312
type PromptOverrides,
1413
promptForGenesisConfig,
@@ -24,6 +23,9 @@ const SECOND_CHAIN_ID = 1;
2423
const SECOND_BLOCK_TIME = 2;
2524
const EVM_STACK_SIZE = 4096;
2625
const CONTRACT_SIZE_LIMIT = 10_000;
26+
const NEGATIVE_PRESET_INT = -1;
27+
const NEGATIVE_BIG_VALUE = "-1";
28+
const NON_NUMERIC_BIG_VALUE = "not-a-number";
2729

2830
const withCancel = <T>(value: T) => {
2931
const promise = Promise.resolve(value) as Promise<T> & { cancel: () => void };
@@ -250,12 +252,12 @@ describe("promptForGenesisConfig", () => {
250252
faucetAddress: faucet,
251253
preset: {
252254
algorithm: ALGORITHM.IBFTv2,
253-
chainId: -1,
254-
secondsPerBlock: -2,
255-
gasLimit: "-5",
256-
gasPrice: -1,
257-
evmStackSize: -3,
258-
contractSizeLimit: -4,
255+
chainId: NEGATIVE_PRESET_INT,
256+
secondsPerBlock: NEGATIVE_PRESET_INT,
257+
gasLimit: NEGATIVE_BIG_VALUE,
258+
gasPrice: NEGATIVE_PRESET_INT,
259+
evmStackSize: NEGATIVE_PRESET_INT,
260+
contractSizeLimit: NEGATIVE_PRESET_INT,
259261
},
260262
validatorAddresses: validators,
261263
})
@@ -273,7 +275,7 @@ describe("promptForGenesisConfig", () => {
273275
chainId: 1,
274276
secondsPerBlock: 1,
275277
gasLimit: "1000",
276-
gasPrice: -1,
278+
gasPrice: NEGATIVE_PRESET_INT,
277279
evmStackSize: 2048,
278280
contractSizeLimit: 100_000,
279281
},
@@ -312,7 +314,7 @@ describe("promptForGenesisConfig", () => {
312314
algorithm: ALGORITHM.IBFTv2,
313315
chainId: 1,
314316
secondsPerBlock: 1,
315-
gasLimit: "not-a-number",
317+
gasLimit: NON_NUMERIC_BIG_VALUE,
316318
gasPrice: 0,
317319
evmStackSize: 2048,
318320
contractSizeLimit: 100_000,
@@ -321,23 +323,4 @@ describe("promptForGenesisConfig", () => {
321323
})
322324
).rejects.toThrow("Gas limit must be a positive integer.");
323325
});
324-
325-
test("ensure helpers validate preset values", () => {
326-
expect(genesisTesting.ensurePositiveInteger(5, "Value")).toBe(5);
327-
expect(genesisTesting.ensureNonNegativeInteger(0, "Zero")).toBe(0);
328-
expect(genesisTesting.ensurePositiveBigIntString("100", "Big")).toBe("100");
329-
330-
expect(() => genesisTesting.ensurePositiveInteger(0, "Value")).toThrow(
331-
"Value must be a positive integer."
332-
);
333-
expect(() => genesisTesting.ensureNonNegativeInteger(-1, "Zero")).toThrow(
334-
"Zero must be a non-negative integer."
335-
);
336-
expect(() => genesisTesting.ensurePositiveBigIntString("0", "Big")).toThrow(
337-
"Big must be a positive integer."
338-
);
339-
expect(() =>
340-
genesisTesting.ensurePositiveBigIntString("bad", "Big")
341-
).toThrow("Big must be a positive integer.");
342-
});
343326
});

src/cli/genesis-prompts.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,3 @@ export type {
239239
GenesisPromptPreset,
240240
};
241241
export { promptForGenesisConfig };
242-
export const __testing = {
243-
ensurePositiveInteger,
244-
ensureNonNegativeInteger,
245-
ensurePositiveBigIntString,
246-
};

0 commit comments

Comments
 (0)