@@ -483,3 +483,110 @@ fn storage_proof_to_raw_json(storage_proof: &sp_state_machine::StorageProof) ->
483483 )
484484 . to_string ( )
485485}
486+
487+ #[ cfg( test) ]
488+ mod tests {
489+ use clap:: Parser ;
490+
491+ use super :: * ;
492+
493+ #[ derive( Parser ) ]
494+ struct TestCli {
495+ #[ command( subcommand) ]
496+ state : State ,
497+ }
498+
499+ /// Multiple URIs via repeated `--uri` flags.
500+ #[ test]
501+ fn uri_repeated_flags ( ) {
502+ let cli = TestCli :: parse_from ( [
503+ "test" ,
504+ "live" ,
505+ "--uri" ,
506+ "ws://localhost:9999" ,
507+ "--uri" ,
508+ "ws://localhost:9998" ,
509+ ] ) ;
510+ match cli. state {
511+ State :: Live ( live) => {
512+ assert_eq ! ( live. uri, vec![ "ws://localhost:9999" , "ws://localhost:9998" ] ) ;
513+ }
514+ _ => panic ! ( "expected Live variant" ) ,
515+ }
516+ }
517+
518+ /// Multiple URIs via comma-separated value in a single `--uri`.
519+ #[ test]
520+ fn uri_comma_separated ( ) {
521+ let cli = TestCli :: parse_from ( [
522+ "test" ,
523+ "live" ,
524+ "--uri" ,
525+ "ws://localhost:9999,ws://localhost:9998" ,
526+ ] ) ;
527+ match cli. state {
528+ State :: Live ( live) => {
529+ assert_eq ! ( live. uri, vec![ "ws://localhost:9999" , "ws://localhost:9998" ] ) ;
530+ }
531+ _ => panic ! ( "expected Live variant" ) ,
532+ }
533+ }
534+
535+ /// Mixing repeated flags with comma-separated values in a single invocation.
536+ #[ test]
537+ fn uri_mixed_repeated_and_comma ( ) {
538+ let cli = TestCli :: parse_from ( [
539+ "test" ,
540+ "live" ,
541+ "--uri" ,
542+ "ws://localhost:9999,ws://localhost:9998" ,
543+ "--uri" ,
544+ "ws://localhost:9997" ,
545+ ] ) ;
546+ match cli. state {
547+ State :: Live ( live) => {
548+ assert_eq ! (
549+ live. uri,
550+ vec![
551+ "ws://localhost:9999" ,
552+ "ws://localhost:9998" ,
553+ "ws://localhost:9997" ,
554+ ]
555+ ) ;
556+ }
557+ _ => panic ! ( "expected Live variant" ) ,
558+ }
559+ }
560+
561+ /// Single URI, the common case.
562+ #[ test]
563+ fn uri_single_value ( ) {
564+ let cli = TestCli :: parse_from ( [ "test" , "live" , "--uri" , "wss://rpc.polkadot.io:443" ] ) ;
565+ match cli. state {
566+ State :: Live ( live) => {
567+ assert_eq ! ( live. uri, vec![ "wss://rpc.polkadot.io:443" ] ) ;
568+ }
569+ _ => panic ! ( "expected Live variant" ) ,
570+ }
571+ }
572+
573+ /// Arguments after `--uri` are not greedily consumed (the original bug).
574+ #[ test]
575+ fn uri_positional_not_swallowed ( ) {
576+ let cli = TestCli :: parse_from ( [
577+ "test" ,
578+ "live" ,
579+ "--uri" ,
580+ "ws://localhost:9999" ,
581+ "--pallet" ,
582+ "System" ,
583+ ] ) ;
584+ match cli. state {
585+ State :: Live ( live) => {
586+ assert_eq ! ( live. uri, vec![ "ws://localhost:9999" ] ) ;
587+ assert_eq ! ( live. pallet, vec![ "System" ] ) ;
588+ }
589+ _ => panic ! ( "expected Live variant" ) ,
590+ }
591+ }
592+ }
0 commit comments