@@ -293,17 +293,12 @@ func TestCentralizedAddresses(t *testing.T) {
293293
294294func TestStartNodeErrors (t * testing.T ) {
295295 baseCtx := context .Background ()
296- // logger variable was declared but not used here, StartNode is called with a new NopLogger below.
297- // I'll create the logger for StartNode when it's called.
298296
299- // Common setup
300297 executor , sequencer , dac , _ , p2pClient , ds , stopDAHeightTicker := createTestComponents (baseCtx , t )
301298 defer stopDAHeightTicker ()
302299
303300 tmpDir := t .TempDir ()
304301
305- // Create a dummy genesis file for successful load cases
306- // Note: StartNode expects genesis relative to ConfigPath's dir, which defaults relative to RootDir
307302 dummyConfigDir := filepath .Join (tmpDir , "config" )
308303 err := os .MkdirAll (dummyConfigDir , 0o755 )
309304 assert .NoError (t , err )
@@ -326,80 +321,70 @@ func TestStartNodeErrors(t *testing.T) {
326321 {
327322 name : "GRPCSignerPanic" ,
328323 configModifier : func (cfg * rollconf.Config ) {
329- cfg .RootDir = tmpDir // Need RootDir for ConfigPath default
324+ cfg .RootDir = tmpDir
330325 cfg .Signer .SignerType = "grpc"
331- cfg .Node .Aggregator = true // Required for signer logic to be hit
326+ cfg .Node .Aggregator = true
332327 },
333- expectPanic : true , // Expects panic("grpc remote signer not implemented")
328+ expectPanic : true ,
334329 },
335330 {
336331 name : "UnknownSignerError" ,
337332 configModifier : func (cfg * rollconf.Config ) {
338- cfg .RootDir = tmpDir // Need RootDir for ConfigPath default
333+ cfg .RootDir = tmpDir
339334 cfg .Signer .SignerType = "unknown"
340- cfg .Node .Aggregator = true // Required for signer logic to be hit
335+ cfg .Node .Aggregator = true
341336 },
342337 expectedError : "unknown remote signer type: unknown" ,
343338 },
344339 {
345340 name : "LoadGenesisError" ,
346341 configModifier : func (cfg * rollconf.Config ) {
347- // Set RootDir to a path where genesis.json won't be found relative to its default config dir
348342 cfg .RootDir = filepath .Join (tmpDir , "nonexistent_root" )
349- // Ensure the directory exists so ConfigPath() doesn't fail early, but genesis won't be there
350343 err := os .MkdirAll (filepath .Join (cfg .RootDir , "config" ), 0o755 )
351344 assert .NoError (t , err )
352345 },
353- expectedError : "failed to load genesis:" , // Check for prefix as the exact error might vary
346+ expectedError : "failed to load genesis:" ,
354347 },
355348 {
356349 name : "LoadFileSystemSignerError" ,
357350 configModifier : func (cfg * rollconf.Config ) {
358- cfg .RootDir = tmpDir // Need RootDir for ConfigPath default
351+ cfg .RootDir = tmpDir
359352 cfg .Node .Aggregator = true
360353 cfg .Signer .SignerType = "file"
361- cfg .Signer .SignerPath = filepath .Join (tmpDir , "nonexistent_signer" ) // Invalid path
354+ cfg .Signer .SignerPath = filepath .Join (tmpDir , "nonexistent_signer" )
362355 },
363- cmdModifier : nil , // Flag is already defined globally, no need to redefine
364- expectedError : "no such file or directory" , // Error from file system
356+ cmdModifier : nil ,
357+ expectedError : "no such file or directory" ,
365358 },
366359 // TODO: Add test case for node.NewNode error if possible with mocks
367360 }
368361
369362 for _ , tc := range testCases {
370363 t .Run (tc .name , func (t * testing.T ) {
371364 nodeConfig := rollconf .DefaultConfig
372- // Apply test-specific config modifications BEFORE potentially using them in newRunNodeCmd
365+
373366 if tc .configModifier != nil {
374367 tc .configModifier (& nodeConfig )
375368 }
376369
377- // Create a signer based on the potentially modified config (needed for newRunNodeCmd)
378- // Use a dummy signer initially, StartNode logic will attempt to load the configured one
379370 dummySigner , _ := filesigner .CreateFileSystemSigner (dummySignerPath , []byte ("password" ))
380371
381- // Pass the potentially modified nodeConfig to newRunNodeCmd
382372 cmd := newRunNodeCmd (baseCtx , executor , sequencer , dac , dummySigner , p2pClient , ds , nodeConfig )
383373
384- // Set the context on the command object before using it
385374 cmd .SetContext (baseCtx )
386375
387- // Apply command modifications (like setting flags) AFTER creating the command
388376 if tc .cmdModifier != nil {
389377 tc .cmdModifier (cmd )
390378 }
391- // for this specific test section
392379 _ = logging .SetLogLevel ("test" , "FATAL" )
393380
394381 runFunc := func () {
395- // Pass the final nodeConfig to StartNode
396382 currentTestLogger := logging .Logger ("TestStartNodeErrors" )
397- _ = logging .SetLogLevel ("TestStartNodeErrors" , "FATAL" ) // NOP behavior
383+ _ = logging .SetLogLevel ("TestStartNodeErrors" , "FATAL" )
398384 err := StartNode (currentTestLogger , cmd , executor , sequencer , dac , p2pClient , ds , nodeConfig , nil )
399385 if tc .expectedError != "" {
400386 assert .ErrorContains (t , err , tc .expectedError )
401387 } else {
402- // If no error is expected (e.g., only panic), ensure no error is returned if it doesn't panic
403388 if ! tc .expectPanic {
404389 assert .NoError (t , err )
405390 }
@@ -410,10 +395,8 @@ func TestStartNodeErrors(t *testing.T) {
410395 assert .Panics (t , runFunc )
411396 } else {
412397 assert .NotPanics (t , runFunc )
413- // Re-check error after NotPanics confirms no panic occurred
414- // Need to re-run StartNode as the original runFunc only checks error if !tc.expectPanic
415398 checkLogger := logging .Logger ("TestStartNodeErrors-check" )
416- _ = logging .SetLogLevel ("TestStartNodeErrors-check" , "FATAL" ) // NOP behavior
399+ _ = logging .SetLogLevel ("TestStartNodeErrors-check" , "FATAL" )
417400 err := StartNode (checkLogger , cmd , executor , sequencer , dac , p2pClient , ds , nodeConfig , nil )
418401 if tc .expectedError != "" {
419402 assert .ErrorContains (t , err , tc .expectedError )
@@ -451,12 +434,10 @@ func newRunNodeCmd(
451434 RunE : func (cmd * cobra.Command , args []string ) error {
452435 runNodeLogger := logging .Logger ("runNodeCmd" )
453436 _ = logging .SetLogLevel ("runNodeCmd" , "FATAL" )
454- // Use the nodeConfig passed into this function closure
455437 return StartNode (runNodeLogger , cmd , executor , sequencer , dac , p2pClient , datastore , nodeConfig , nil )
456438 },
457439 }
458440
459- // Add Rollkit flags
460441 rollconf .AddFlags (cmd )
461442 rollconf .AddGlobalFlags (cmd , "" )
462443
0 commit comments