@@ -492,3 +492,159 @@ func TestParseChanIDs(t *testing.T) {
492
492
})
493
493
}
494
494
}
495
+
496
+ // TestFlagParsing tests parsing of various commands.
497
+ func TestFlagParsing (t * testing.T ) {
498
+ t .Parallel ()
499
+
500
+ testCases := []struct {
501
+ name string
502
+ cmd cli.Command
503
+ args []string
504
+ expectedErrMsg string
505
+ }{
506
+ {
507
+ name : "closechannel valid" ,
508
+ cmd : closeChannelCommand ,
509
+ args : []string {
510
+ "lncli" , "closechannel" ,
511
+ "--sat_per_vbyte" , "30" ,
512
+ },
513
+ },
514
+ {
515
+ name : "closechannel valid, zero feerate" ,
516
+ cmd : closeChannelCommand ,
517
+ args : []string {
518
+ "lncli" , "closechannel" ,
519
+ "--sat_per_vbyte" , "0" ,
520
+ },
521
+ },
522
+ {
523
+ name : "closechannel valid, max u64 feerate" ,
524
+ cmd : closeChannelCommand ,
525
+ args : []string {
526
+ "lncli" , "closechannel" ,
527
+ "--sat_per_vbyte" ,
528
+ strconv .FormatUint (math .MaxUint64 , 10 ),
529
+ },
530
+ },
531
+ {
532
+ name : "closechannel invalid, negative feerate" ,
533
+ cmd : closeChannelCommand ,
534
+ args : []string {
535
+ "lncli" , "closechannel" ,
536
+ "--sat_per_vbyte" , "-1" ,
537
+ },
538
+ expectedErrMsg : "parse error" ,
539
+ },
540
+ {
541
+ name : "closechannel invalid, non-numeric feerate" ,
542
+ cmd : closeChannelCommand ,
543
+ args : []string {
544
+ "lncli" , "closechannel" ,
545
+ "--sat_per_vbyte" , "abc" ,
546
+ },
547
+ expectedErrMsg : "parse error" ,
548
+ },
549
+ {
550
+ name : "channelopen valid" ,
551
+ cmd : openChannelCommand ,
552
+ args : []string {
553
+ "lncli" , "openchannel" ,
554
+ "--sat_per_vbyte" , "50" ,
555
+ "--node_key" , "pubkey" ,
556
+ "--local_amt" , "100000" ,
557
+ },
558
+ },
559
+ {
560
+ name : "channelopen invalid, negative feerate" ,
561
+ cmd : openChannelCommand ,
562
+ args : []string {
563
+ "lncli" , "openchannel" ,
564
+ "--sat_per_vbyte" , "-1" ,
565
+ "--node_key" , "pubkey" ,
566
+ "--local_amt" , "100000" ,
567
+ },
568
+ expectedErrMsg : "parse error" ,
569
+ },
570
+ {
571
+ name : "sendcoins valid" ,
572
+ cmd : sendCoinsCommand ,
573
+ args : []string {
574
+ "lncli" , "sendcoins" ,
575
+ "--sat_per_vbyte" , "30" ,
576
+ "--addr" , "bc1qexample" ,
577
+ "--amt" , "1000" ,
578
+ },
579
+ },
580
+ {
581
+ name : "sendcoins invalid, negative feerate" ,
582
+ cmd : sendCoinsCommand ,
583
+ args : []string {
584
+ "lncli" , "sendcoins" ,
585
+ "--sat_per_vbyte" , "-1" ,
586
+ "--addr" , "bc1qexample" ,
587
+ "--amt" , "1000" ,
588
+ },
589
+ expectedErrMsg : "parse error" ,
590
+ },
591
+ {
592
+ name : "sendmany valid" ,
593
+ cmd : sendManyCommand ,
594
+ args : []string {
595
+ "lncli" , "sendmany" ,
596
+ "--sat_per_vbyte" , "40" ,
597
+ `{"bc1qexample": 500}` ,
598
+ },
599
+ },
600
+ {
601
+ name : "sendmany invalid, negative feerate" ,
602
+ cmd : sendManyCommand ,
603
+ args : []string {
604
+ "lncli" , "sendmany" ,
605
+ "--sat_per_vbyte" , "-1" ,
606
+ `{"bc1qexample": 500}` ,
607
+ },
608
+ expectedErrMsg : "parse error" ,
609
+ },
610
+ {
611
+ name : "closeallchannels valid" ,
612
+ cmd : closeAllChannelsCommand ,
613
+ args : []string {
614
+ "lncli" , "closeallchannels" ,
615
+ "--sat_per_vbyte" , "60" ,
616
+ },
617
+ },
618
+ {
619
+ name : "closeallchannels invalid, negative feerate" ,
620
+ cmd : closeAllChannelsCommand ,
621
+ args : []string {
622
+ "lncli" , "closeallchannels" ,
623
+ "--sat_per_vbyte" , "-1" ,
624
+ },
625
+ expectedErrMsg : "parse error" ,
626
+ },
627
+ }
628
+
629
+ for _ , tc := range testCases {
630
+ t .Run (tc .name , func (t * testing.T ) {
631
+ cmd := tc .cmd
632
+
633
+ // Disable the action so action doesn't run.
634
+ cmd .Action = func (ctx * cli.Context ) error {
635
+ return nil
636
+ }
637
+
638
+ app := & cli.App {
639
+ Commands : []cli.Command {cmd },
640
+ }
641
+
642
+ err := app .Run (tc .args )
643
+ if tc .expectedErrMsg != "" {
644
+ require .ErrorContains (t , err , tc .expectedErrMsg )
645
+ } else {
646
+ require .NoError (t , err )
647
+ }
648
+ })
649
+ }
650
+ }
0 commit comments