@@ -23,6 +23,7 @@ const {
2323 genesisConfigMapName : DEFAULT_GENESIS_CONFIGMAP_NAME ,
2424 staticNodesConfigMapName : DEFAULT_STATIC_NODES_CONFIGMAP_NAME ,
2525 faucetArtifactPrefix : DEFAULT_FAUCET_PREFIX ,
26+ subgraphConfigMapName : DEFAULT_SUBGRAPH_CONFIGMAP_NAME ,
2627} = ARTIFACT_DEFAULTS ;
2728const UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04" ;
2829const UNCOMPRESSED_PUBLIC_KEY_LENGTH = 130 ;
@@ -35,6 +36,8 @@ const PUBLIC_KEY_REPEAT = 64;
3536const FIRST_VALIDATOR_INDEX = 1 ;
3637const SECOND_VALIDATOR_INDEX = 2 ;
3738const FAUCET_INDEX = VALIDATOR_RETURN + 1 ;
39+ const SAMPLE_SUBGRAPH_HASH =
40+ "bafybeigdyrztzd4gufq2bdsd6we3jh7uzulnd2ipkyli5sto6f5j6rlude" ;
3841const createFactoryStub = ( ) => {
3942 let counter = 0 ;
4043 return {
@@ -204,6 +207,7 @@ describe("CLI command bootstrap", () => {
204207 loadAbisPath = path ;
205208 return Promise . resolve ( [ ] ) ;
206209 } ,
210+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
207211 outputResult : async ( type , payload ) => {
208212 outputInvocation = { type, payload } ;
209213 await realOutputResult ( type , payload ) ;
@@ -242,6 +246,7 @@ describe("CLI command bootstrap", () => {
242246 validatorPrefix : DEFAULT_POD_PREFIX ,
243247 genesisConfigMapName : DEFAULT_GENESIS_CONFIGMAP_NAME ,
244248 staticNodesConfigMapName : DEFAULT_STATIC_NODES_CONFIGMAP_NAME ,
249+ subgraphConfigMapName : DEFAULT_SUBGRAPH_CONFIGMAP_NAME ,
245250 } ) ;
246251 } ) ;
247252
@@ -278,6 +283,7 @@ describe("CLI command bootstrap", () => {
278283 capturedAbiPath = path ;
279284 return Promise . resolve ( abiArtifacts ) ;
280285 } ,
286+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
281287 outputResult : ( _type , payload ) => {
282288 capturedPayload = payload ;
283289 return Promise . resolve ( ) ;
@@ -296,6 +302,56 @@ describe("CLI command bootstrap", () => {
296302 expect ( capturedPayload ?. abiArtifacts ) . toEqual ( abiArtifacts ) ;
297303 } ) ;
298304
305+ test ( "runBootstrap loads subgraph hash from environment" , async ( ) => {
306+ const factory = createFactoryStub ( ) ;
307+ let capturedPath : string | undefined ;
308+ let capturedPayload : OutputPayload | undefined ;
309+ const originalEnv = Bun . env . SUBGRAPH_HASH_FILE ;
310+
311+ const deps : BootstrapDependencies = {
312+ factory,
313+ promptForCount : ( ) => Promise . resolve ( EXPECTED_DEFAULT_VALIDATOR ) ,
314+ promptForGenesis : async ( _service , { faucetAddress } ) => ( {
315+ algorithm : ALGORITHM . QBFT ,
316+ config : {
317+ chainId : 1 ,
318+ faucetWalletAddress : faucetAddress ,
319+ gasLimit : "0x1" ,
320+ secondsPerBlock : 2 ,
321+ } ,
322+ genesis : { config : { } , extraData : "0x" } as any ,
323+ } ) ,
324+ promptForText : passthroughTextPrompt ,
325+ service : { } as any ,
326+ loadAllocations : ( ) =>
327+ Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
328+ loadAbis : ( ) => Promise . resolve ( [ ] ) ,
329+ loadSubgraphHash : ( path : string ) => {
330+ capturedPath = path ;
331+ return Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ;
332+ } ,
333+ outputResult : ( _type , payload ) => {
334+ capturedPayload = payload ;
335+ return Promise . resolve ( ) ;
336+ } ,
337+ } ;
338+
339+ Bun . env . SUBGRAPH_HASH_FILE = " /tmp/subgraph.txt " ;
340+
341+ try {
342+ await runBootstrap ( { acceptDefaults : true } , deps ) ;
343+ } finally {
344+ if ( originalEnv === undefined ) {
345+ Bun . env . SUBGRAPH_HASH_FILE = undefined ;
346+ } else {
347+ Bun . env . SUBGRAPH_HASH_FILE = originalEnv ;
348+ }
349+ }
350+
351+ expect ( capturedPath ) . toBe ( "/tmp/subgraph.txt" ) ;
352+ expect ( capturedPayload ?. subgraphHash ) . toBe ( SAMPLE_SUBGRAPH_HASH ) ;
353+ } ) ;
354+
299355 test ( "createCliCommand wires metadata" , ( ) => {
300356 const command = createCliCommand ( ) ;
301357 expect ( command . name ( ) ) . toBe ( "network-bootstrapper" ) ;
@@ -337,6 +393,7 @@ describe("CLI command bootstrap", () => {
337393 loadAllocations : ( ) =>
338394 Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
339395 loadAbis : ( ) => Promise . resolve ( [ ] ) ,
396+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
340397 outputResult : async ( type , payload ) => {
341398 await realOutputResult ( type , payload ) ;
342399 } ,
@@ -405,6 +462,7 @@ describe("CLI command bootstrap", () => {
405462 loadAllocations : ( ) =>
406463 Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
407464 loadAbis : ( ) => Promise . resolve ( [ ] ) ,
465+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
408466 outputResult : ( _type , payload ) => {
409467 capturedPayload = payload ;
410468 return Promise . resolve ( ) ;
@@ -457,6 +515,7 @@ describe("CLI command bootstrap", () => {
457515 validatorPrefix : "custom-validator" ,
458516 genesisConfigMapName : "custom-genesis" ,
459517 staticNodesConfigMapName : "custom-static-nodes" ,
518+ subgraphConfigMapName : DEFAULT_SUBGRAPH_CONFIGMAP_NAME ,
460519 } ) ;
461520 } ) ;
462521
@@ -487,6 +546,7 @@ describe("CLI command bootstrap", () => {
487546 loadAllocations : ( ) =>
488547 Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
489548 loadAbis : ( ) => Promise . resolve ( [ ] ) ,
549+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
490550 outputResult : ( _type , payload ) => {
491551 capturedPayload = payload ;
492552 return Promise . resolve ( ) ;
@@ -556,6 +616,7 @@ describe("CLI command bootstrap", () => {
556616 loadAllocations : ( ) =>
557617 Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
558618 loadAbis : ( ) => Promise . resolve ( [ ] ) ,
619+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
559620 outputResult : async ( ) => {
560621 // no-op for test
561622 } ,
@@ -639,6 +700,7 @@ describe("CLI command bootstrap", () => {
639700 loadAllocations : ( ) =>
640701 Promise . resolve ( { } satisfies Record < string , BesuAllocAccount > ) ,
641702 loadAbis : ( ) => Promise . resolve ( [ ] ) ,
703+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
642704 outputResult : ( type ) => {
643705 capturedOutputType = type ;
644706 return Promise . resolve ( ) ;
@@ -730,13 +792,15 @@ describe("CLI command bootstrap", () => {
730792 loadAbisInvoked = true ;
731793 return Promise . resolve ( [ ] ) ;
732794 } ,
795+ loadSubgraphHash : ( ) => Promise . resolve ( SAMPLE_SUBGRAPH_HASH ) ,
733796 outputResult : ( _type , payload ) => {
734797 expect ( payload . validators ) . toHaveLength ( EXPECTED_DEFAULT_VALIDATOR ) ;
735798 expect ( payload . artifactNames ) . toEqual ( {
736799 faucetPrefix : DEFAULT_FAUCET_PREFIX ,
737800 validatorPrefix : DEFAULT_POD_PREFIX ,
738801 genesisConfigMapName : DEFAULT_GENESIS_CONFIGMAP_NAME ,
739802 staticNodesConfigMapName : DEFAULT_STATIC_NODES_CONFIGMAP_NAME ,
803+ subgraphConfigMapName : DEFAULT_SUBGRAPH_CONFIGMAP_NAME ,
740804 } ) ;
741805 return Promise . resolve ( ) ;
742806 } ,
0 commit comments