Skip to content

Commit 8edeecb

Browse files
committed
fix(tests): standardize algorithm naming in tests
- Updated algorithm references in test cases from uppercase to lowercase (e.g., ALGORITHM.QBFT to ALGORITHM.qbft) for consistency. - Ensured that all related tests reflect the updated naming convention, improving clarity and maintainability. - Adjusted expected outputs in various test files to align with the new algorithm naming.
1 parent 10607ea commit 8edeecb

10 files changed

+51
-47
lines changed

src/cli/commands/bootstrap/bootstrap.allocations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("loadAllocations", () => {
5555
});
5656

5757
test("throws on invalid address", async () => {
58-
const allocations = { INVALID: { balance: "0x01" } };
58+
const allocations = { invalidAddress: { balance: "0x01" } };
5959
const { dir, path } = createTempFile(JSON.stringify(allocations));
6060

6161
await expect(loadAllocations(path)).rejects.toThrow(INVALID_ADDRESS_ERROR);

src/cli/commands/bootstrap/bootstrap.command.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("CLI command bootstrap", () => {
182182
contractSizeLimit: undefined,
183183
});
184184
return Promise.resolve({
185-
algorithm: ALGORITHM.QBFT,
185+
algorithm: ALGORITHM.qbft,
186186
config: {
187187
chainId: 99,
188188
faucetWalletAddress: faucetAddress,
@@ -266,7 +266,7 @@ describe("CLI command bootstrap", () => {
266266
factory,
267267
promptForCount: () => Promise.resolve(EXPECTED_DEFAULT_VALIDATOR),
268268
promptForGenesis: async (_service, { faucetAddress }) => ({
269-
algorithm: ALGORITHM.QBFT,
269+
algorithm: ALGORITHM.qbft,
270270
config: {
271271
chainId: 1,
272272
faucetWalletAddress: faucetAddress,
@@ -312,7 +312,7 @@ describe("CLI command bootstrap", () => {
312312
factory,
313313
promptForCount: () => Promise.resolve(EXPECTED_DEFAULT_VALIDATOR),
314314
promptForGenesis: async (_service, { faucetAddress }) => ({
315-
algorithm: ALGORITHM.QBFT,
315+
algorithm: ALGORITHM.qbft,
316316
config: {
317317
chainId: 1,
318318
faucetWalletAddress: faucetAddress,
@@ -368,7 +368,7 @@ describe("CLI command bootstrap", () => {
368368
},
369369
promptForGenesis: (_service, { preset }) => {
370370
expect(preset).toEqual({
371-
algorithm: ALGORITHM.QBFT,
371+
algorithm: ALGORITHM.qbft,
372372
chainId: 55,
373373
secondsPerBlock: 3,
374374
gasLimit: "5000000",
@@ -377,7 +377,7 @@ describe("CLI command bootstrap", () => {
377377
contractSizeLimit: 10_000,
378378
});
379379
return Promise.resolve({
380-
algorithm: preset?.algorithm ?? ALGORITHM.QBFT,
380+
algorithm: preset?.algorithm ?? ALGORITHM.qbft,
381381
config: {
382382
chainId: preset?.chainId ?? 1,
383383
faucetWalletAddress: expectedAddress(VALIDATOR_RETURN + 1),
@@ -448,7 +448,7 @@ describe("CLI command bootstrap", () => {
448448
Promise.resolve(provided ?? defaultValue),
449449
promptForGenesis: (_service, { faucetAddress }) =>
450450
Promise.resolve({
451-
algorithm: ALGORITHM.QBFT,
451+
algorithm: ALGORITHM.qbft,
452452
config: {
453453
chainId: 77,
454454
faucetWalletAddress: faucetAddress,
@@ -531,7 +531,7 @@ describe("CLI command bootstrap", () => {
531531
expect(validatorAddresses).toHaveLength(1);
532532
expect(faucetAddress).toBe(expectedAddress(2));
533533
return Promise.resolve({
534-
algorithm: ALGORITHM.QBFT,
534+
algorithm: ALGORITHM.qbft,
535535
config: {
536536
chainId: 123,
537537
faucetWalletAddress: faucetAddress,
@@ -592,7 +592,7 @@ describe("CLI command bootstrap", () => {
592592
promptForGenesis: (_service, { preset, autoAcceptDefaults }) => {
593593
expect(autoAcceptDefaults).toBe(false);
594594
expect(preset).toEqual({
595-
algorithm: ALGORITHM.IBFTv2,
595+
algorithm: ALGORITHM.ibftV2,
596596
chainId: 1234,
597597
secondsPerBlock: 6,
598598
gasLimit: "1000000",
@@ -601,7 +601,7 @@ describe("CLI command bootstrap", () => {
601601
contractSizeLimit: 100_000,
602602
});
603603
return Promise.resolve({
604-
algorithm: ALGORITHM.IBFTv2,
604+
algorithm: ALGORITHM.ibftV2,
605605
config: {
606606
chainId: 1234,
607607
faucetWalletAddress: expectedAddress(validatorOverride + 1),
@@ -624,7 +624,7 @@ describe("CLI command bootstrap", () => {
624624

625625
const options: CliOptions = {
626626
validators: validatorOverride,
627-
consensus: ALGORITHM.IBFTv2,
627+
consensus: ALGORITHM.ibftV2,
628628
chainId: 1234,
629629
secondsPerBlock: 6,
630630
gasLimit: "1000000",
@@ -685,7 +685,7 @@ describe("CLI command bootstrap", () => {
685685
factory: createFactoryStub(),
686686
promptForCount: () => Promise.resolve(EXPECTED_DEFAULT_VALIDATOR),
687687
promptForGenesis: async () => ({
688-
algorithm: ALGORITHM.QBFT,
688+
algorithm: ALGORITHM.qbft,
689689
config: {
690690
chainId: 1,
691691
faucetWalletAddress: expectedAddress(EXPECTED_DEFAULT_VALIDATOR + 1),
@@ -770,7 +770,7 @@ describe("CLI command bootstrap", () => {
770770
});
771771

772772
return Promise.resolve({
773-
algorithm: ALGORITHM.QBFT,
773+
algorithm: ALGORITHM.qbft,
774774
config: {
775775
chainId: 1,
776776
faucetWalletAddress: expectedAddress(

src/cli/commands/bootstrap/bootstrap.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ const createCliCommand = (
546546
.option(
547547
"--consensus <algorithm>",
548548
`Consensus algorithm (${Object.values(ALGORITHM).join(", ")}). (default: ${
549-
ALGORITHM.QBFT
549+
ALGORITHM.qbft
550550
})`,
551551
(value: string): Algorithm => {
552552
const normalized = stripSurroundingQuotes(value).toLowerCase();

src/cli/commands/bootstrap/bootstrap.genesis-prompts.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe("promptForGenesisConfig", () => {
127127
`${EVM_STACK_SIZE}`,
128128
`${CONTRACT_SIZE_LIMIT}`,
129129
],
130-
algorithm: "IBFTv2",
130+
algorithm: "ibftV2",
131131
});
132132

133133
const result = await promptForGenesisConfig(
@@ -140,7 +140,7 @@ describe("promptForGenesisConfig", () => {
140140
}
141141
);
142142

143-
expect(result.algorithm).toBe(ALGORITHM.IBFTv2);
143+
expect(result.algorithm).toBe(ALGORITHM.ibftV2);
144144
expect(result.config.chainId).toBe(CHAIN_ID_RESPONSE);
145145
expect(result.config.secondsPerBlock).toBe(BLOCK_TIME_RESPONSE);
146146
expect(result.config.gasPrice).toBe(GAS_PRICE_RESPONSE);
@@ -168,7 +168,7 @@ describe("promptForGenesisConfig", () => {
168168
`${EVM_STACK_SIZE}`,
169169
`${CONTRACT_SIZE_LIMIT}`,
170170
],
171-
algorithm: "QBFT",
171+
algorithm: "qbft",
172172
});
173173

174174
const result = await promptForGenesisConfig(
@@ -181,14 +181,14 @@ describe("promptForGenesisConfig", () => {
181181
}
182182
);
183183

184-
expect(result.algorithm).toBe(ALGORITHM.QBFT);
184+
expect(result.algorithm).toBe(ALGORITHM.qbft);
185185
expect(result.config.gasPrice).toBeUndefined();
186186
});
187187

188188
test("uses preset values without prompting", async () => {
189189
const { service } = createServiceStub();
190190
const preset = {
191-
algorithm: ALGORITHM.QBFT,
191+
algorithm: ALGORITHM.qbft,
192192
chainId: 6543,
193193
secondsPerBlock: 7,
194194
gasLimit: "123456789",
@@ -221,7 +221,7 @@ describe("promptForGenesisConfig", () => {
221221
}
222222
);
223223

224-
expect(result.algorithm).toBe(ALGORITHM.QBFT);
224+
expect(result.algorithm).toBe(ALGORITHM.qbft);
225225
expect(result.config.chainId).toBe(preset.chainId);
226226
expect(result.config.secondsPerBlock).toBe(preset.secondsPerBlock);
227227
expect(result.config.gasLimit).toBe(
@@ -256,7 +256,7 @@ describe("promptForGenesisConfig", () => {
256256
allocations: {} as Record<string, BesuAllocAccount>,
257257
faucetAddress: faucet,
258258
preset: {
259-
algorithm: ALGORITHM.IBFTv2,
259+
algorithm: ALGORITHM.ibftV2,
260260
chainId: NEGATIVE_PRESET_INT,
261261
secondsPerBlock: NEGATIVE_PRESET_INT,
262262
gasLimit: NEGATIVE_BIG_VALUE,
@@ -276,7 +276,7 @@ describe("promptForGenesisConfig", () => {
276276
allocations: {} as Record<string, BesuAllocAccount>,
277277
faucetAddress: faucet,
278278
preset: {
279-
algorithm: ALGORITHM.QBFT,
279+
algorithm: ALGORITHM.qbft,
280280
chainId: 1,
281281
secondsPerBlock: 1,
282282
gasLimit: "1000",
@@ -296,7 +296,7 @@ describe("promptForGenesisConfig", () => {
296296
allocations: {} as Record<string, BesuAllocAccount>,
297297
faucetAddress: faucet,
298298
preset: {
299-
algorithm: ALGORITHM.IBFTv2,
299+
algorithm: ALGORITHM.ibftV2,
300300
chainId: 1,
301301
secondsPerBlock: 1,
302302
gasLimit: "-5",
@@ -316,7 +316,7 @@ describe("promptForGenesisConfig", () => {
316316
allocations: {} as Record<string, BesuAllocAccount>,
317317
faucetAddress: faucet,
318318
preset: {
319-
algorithm: ALGORITHM.IBFTv2,
319+
algorithm: ALGORITHM.ibftV2,
320320
chainId: 1,
321321
secondsPerBlock: 1,
322322
gasLimit: NON_NUMERIC_BIG_VALUE,
@@ -361,7 +361,7 @@ describe("promptForGenesisConfig", () => {
361361

362362
const expectedChainId =
363363
Math.floor(RANDOM_HALF * CHAIN_ID_RANGE) + MIN_CHAIN_ID;
364-
expect(result.algorithm).toBe(ALGORITHM.QBFT);
364+
expect(result.algorithm).toBe(ALGORITHM.qbft);
365365
expect(result.config.chainId).toBe(expectedChainId);
366366
expect(result.config.secondsPerBlock).toBe(2);
367367
expect(result.config.gasLimit).toBe(

src/cli/commands/bootstrap/bootstrap.genesis-prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const promptForGenesisConfig = async (
118118

119119
const defaults = createDefaultNetworkSettings();
120120

121-
const fallbackAlgorithm = ALGORITHM.QBFT;
121+
const fallbackAlgorithm = ALGORITHM.qbft;
122122

123123
let resolvedAlgorithm: Algorithm;
124124
if (preset?.algorithm) {

src/cli/commands/bootstrap/bootstrap.output.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ const toAllocationConfigMapName = (address: string): string =>
257257

258258
const genesisService = new BesuGenesisService(TEST_CHAIN_ID);
259259
const sampleGenesis = genesisService.generate(
260-
ALGORITHM.QBFT,
260+
ALGORITHM.qbft,
261261
{
262262
chainId: TEST_CHAIN_ID,
263263
faucetWalletAddress: sampleFaucet.address,
@@ -527,9 +527,9 @@ describe("outputResult", () => {
527527
(entry) => entry.name === "besu-subgraph"
528528
);
529529
expect(subgraphConfig?.immutable).toBe(true);
530-
// Kubernetes configmaps store the raw IPFS hash; local file output adds the kit: prefix.
530+
// Kubernetes ConfigMaps store the kit-prefixed hash to match local file output.
531531
expect(subgraphConfig?.data?.[SUBGRAPH_HASH_KEY]).toBe(
532-
SAMPLE_SUBGRAPH_HASH
532+
`kit:${SAMPLE_SUBGRAPH_HASH}`
533533
);
534534
} finally {
535535
(KubeConfig.prototype as any).loadFromCluster = originalLoad;

src/cli/commands/bootstrap/bootstrap.output.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type SecretSpec = SecretEntrySpec;
5151
const OUTPUT_DIR = "out";
5252
const MILLISECOND_PAD_WIDTH = 3;
5353
const ZERO_BALANCE = "0x0";
54+
const KIT_PREFIX = "kit:";
55+
56+
const formatSubgraphHash = (hash: string): string =>
57+
hash.startsWith(KIT_PREFIX) ? hash : `${KIT_PREFIX}${hash}`;
5458

5559
const logNonScreenStep = (message: string): void => {
5660
process.stdout.write(`${muted(`[bootstrap] ${message}`)}\n`);
@@ -234,7 +238,7 @@ const outputToFile = async (payload: OutputPayload): Promise<string> => {
234238
path: join(directory, `${artifactNames.subgraphConfigMapName}.json`),
235239
description: `${artifactNames.subgraphConfigMapName}.json`,
236240
contents: `${JSON.stringify(
237-
{ [SUBGRAPH_HASH_KEY]: `kit:${payload.subgraphHash}` },
241+
{ [SUBGRAPH_HASH_KEY]: formatSubgraphHash(payload.subgraphHash) },
238242
null,
239243
2
240244
)}\n`,
@@ -295,7 +299,7 @@ const outputToKubernetes = async (payload: OutputPayload): Promise<void> => {
295299
configMapSpecs.push({
296300
name: artifactNames.subgraphConfigMapName,
297301
key: SUBGRAPH_HASH_KEY,
298-
value: payload.subgraphHash,
302+
value: formatSubgraphHash(payload.subgraphHash),
299303
immutable: true,
300304
onConflict: "skip",
301305
});

src/cli/commands/compile-genesis/compile-genesis.command.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const SAMPLE_ACCOUNT: BesuAllocAccount = {
3333

3434
const genesisService = new BesuGenesisService();
3535
const baseGenesis = genesisService.generate(
36-
ALGORITHM.QBFT,
36+
ALGORITHM.qbft,
3737
{
3838
chainId: 1337,
3939
faucetWalletAddress: FAUCET_ADDRESS,

src/genesis/besu-genesis.service.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const baseConfig = {
2424

2525
describe("BesuGenesisService", () => {
2626
test("generate builds base genesis", () => {
27-
const genesis = service.generate(ALGORITHM.QBFT, baseConfig);
27+
const genesis = service.generate(ALGORITHM.qbft, baseConfig);
2828

2929
expect(genesis.config.chainId).toBe(CHAIN_ID);
3030
expect(genesis.gasLimit).toBe(GAS_LIMIT);
@@ -37,15 +37,15 @@ describe("BesuGenesisService", () => {
3737
[FAUCET]: { balance: "0x02" as const },
3838
};
3939
const withContracts = service.generate(
40-
ALGORITHM.QBFT,
40+
ALGORITHM.qbft,
4141
baseConfig,
4242
overrides
4343
);
4444
expect(withContracts.alloc[FAUCET]?.balance).toBe("0x02");
4545
});
4646

4747
test("generate configures IBFT consensus", () => {
48-
const genesis = service.generate(ALGORITHM.IBFTv2, baseConfig);
48+
const genesis = service.generate(ALGORITHM.ibftV2, baseConfig);
4949
const consensus = genesis.config.ibft2;
5050
expect(consensus).toBeDefined();
5151
expect(consensus?.blockperiodseconds).toBe(baseConfig.secondsPerBlock);
@@ -56,7 +56,7 @@ describe("BesuGenesisService", () => {
5656
});
5757

5858
test("generate configures QBFT consensus", () => {
59-
const genesis = service.generate(ALGORITHM.QBFT, baseConfig);
59+
const genesis = service.generate(ALGORITHM.qbft, baseConfig);
6060
const consensus = genesis.config.qbft;
6161
expect(consensus).toBeDefined();
6262
expect(consensus?.blockperiodseconds).toBe(baseConfig.secondsPerBlock);
@@ -66,9 +66,9 @@ describe("BesuGenesisService", () => {
6666
test("private helpers expose consensus configuration", () => {
6767
const bft = (
6868
service as unknown as {
69-
generateBFT: (config: typeof baseConfig) => unknown;
69+
generateBft: (config: typeof baseConfig) => unknown;
7070
}
71-
).generateBFT(baseConfig);
71+
).generateBft(baseConfig);
7272
expect(
7373
(bft as { requesttimeoutseconds: number }).requesttimeoutseconds
7474
).toBeGreaterThan(0);
@@ -80,7 +80,7 @@ describe("BesuGenesisService", () => {
8080
config: typeof baseConfig
8181
) => unknown;
8282
}
83-
).buildConsensusConfig(ALGORITHM.IBFTv2, baseConfig);
83+
).buildConsensusConfig(ALGORITHM.ibftV2, baseConfig);
8484
expect(consensus).toHaveProperty("ibft2");
8585

8686
const alloc = (
@@ -94,7 +94,7 @@ describe("BesuGenesisService", () => {
9494
expect(alloc).toHaveProperty(FAUCET);
9595
});
9696

97-
const algorithms: Algorithm[] = [ALGORITHM.IBFTv2, ALGORITHM.QBFT];
97+
const algorithms: Algorithm[] = [ALGORITHM.ibftV2, ALGORITHM.qbft];
9898

9999
for (const algorithm of algorithms) {
100100
test(`computeExtraData for ${algorithm}`, () => {

src/genesis/besu-genesis.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Hex, Rlp } from "ox";
33
type HexString = Hex.Hex;
44

55
export const ALGORITHM = {
6-
IBFTv2: "IBFTv2",
7-
QBFT: "QBFT",
6+
ibftV2: "IBFTv2",
7+
qbft: "QBFT",
88
} as const;
99

1010
export type Algorithm = (typeof ALGORITHM)[keyof typeof ALGORITHM];
@@ -143,7 +143,7 @@ export class BesuGenesisService {
143143
Hex.assert(validator, { strict: true });
144144
return validator as HexString;
145145
});
146-
if (algorithm === ALGORITHM.IBFTv2) {
146+
if (algorithm === ALGORITHM.ibftV2) {
147147
return Rlp.fromHex([VANITY_DATA, normalized, EMPTY_HEX, ROUND_ZERO, []]);
148148
}
149149

@@ -154,14 +154,14 @@ export class BesuGenesisService {
154154
algorithm: Algorithm,
155155
config: BesuNetworkConfig
156156
): Partial<Pick<BesuGenesisConfig, "ibft2" | "qbft">> {
157-
if (algorithm === ALGORITHM.IBFTv2) {
158-
return { ibft2: this.generateBFT(config) };
157+
if (algorithm === ALGORITHM.ibftV2) {
158+
return { ibft2: this.generateBft(config) };
159159
}
160160

161-
return { qbft: this.generateBFT(config) };
161+
return { qbft: this.generateBft(config) };
162162
}
163163

164-
private generateBFT(config: BesuNetworkConfig): BesuBftConfig {
164+
private generateBft(config: BesuNetworkConfig): BesuBftConfig {
165165
const timeout = Math.floor(
166166
Math.max(MINIMUM_BFT_BLOCK_PERIOD_SECONDS, config.secondsPerBlock) +
167167
Math.max(

0 commit comments

Comments
 (0)