@@ -30,6 +30,20 @@ import (
30
30
var zeroCircuit = channeldb.CircuitKey {}
31
31
var emptyScid = lnwire.ShortChannelID {}
32
32
33
+ type SuccessOrFailureOption string
34
+
35
+ const (
36
+ Success SuccessOrFailureOption = "success"
37
+ PeerOffline = "peerOffline"
38
+ UnknownChannel = "unknownChannel"
39
+ )
40
+
41
+ var SuccessOrFailureOptions = []SuccessOrFailureOption {
42
+ Success ,
43
+ PeerOffline ,
44
+ UnknownChannel ,
45
+ }
46
+
33
47
func genPreimage () ([32 ]byte , error ) {
34
48
var preimage [32 ]byte
35
49
if _ , err := io .ReadFull (rand .Reader , preimage [:]); err != nil {
@@ -656,22 +670,40 @@ func TestSwitchSendHTLCMapping(t *testing.T) {
656
670
TxPosition : 45 ,
657
671
},
658
672
},
673
+ {
674
+ name : "zero-conf unknown scid" ,
675
+ zeroConf : true ,
676
+ useAlias : false ,
677
+ alias : lnwire.ShortChannelID {
678
+ BlockHeight : 10035 ,
679
+ TxIndex : 35 ,
680
+ TxPosition : 35 ,
681
+ },
682
+ real : lnwire.ShortChannelID {
683
+ BlockHeight : 470000 ,
684
+ TxIndex : 35 ,
685
+ TxPosition : 45 ,
686
+ },
687
+ },
659
688
}
660
689
661
- for _ , test := range tests {
662
- test := test
663
- t .Run (test .name , func (t * testing.T ) {
664
- t .Parallel ()
665
- testSwitchSendHtlcMapping (
666
- t , test .zeroConf , test .useAlias , test .alias ,
667
- test .real , test .optionFeature ,
668
- )
669
- })
690
+ for _ , successOrFailure := range SuccessOrFailureOptions {
691
+ for _ , test := range tests {
692
+ test := test
693
+ testName := fmt .Sprintf ("%s[%s]" , test .name , successOrFailure )
694
+ t .Run (testName , func (t * testing.T ) {
695
+ testSwitchSendHtlcMapping (
696
+ t , test .zeroConf , test .useAlias , test .alias ,
697
+ test .real , test .optionFeature , successOrFailure ,
698
+ )
699
+ })
700
+ }
670
701
}
671
702
}
672
703
673
704
func testSwitchSendHtlcMapping (t * testing.T , zeroConf , useAlias bool , alias ,
674
- realScid lnwire.ShortChannelID , optionFeature bool ) {
705
+ realScid lnwire.ShortChannelID , optionFeature bool ,
706
+ successOrFailureOption SuccessOrFailureOption ) {
675
707
676
708
peer , err := newMockServer (
677
709
t , "alice" , testStartingHeight , nil , testDefaultDelta ,
@@ -708,6 +740,10 @@ func testSwitchSendHtlcMapping(t *testing.T, zeroConf, useAlias bool, alias,
708
740
err = s .AddLink (link )
709
741
require .NoError (t , err )
710
742
743
+ if successOrFailureOption == PeerOffline {
744
+ s .RemoveLink (link .chanID )
745
+ }
746
+
711
747
// Generate preimage.
712
748
preimage , err := genPreimage ()
713
749
require .NoError (t , err )
@@ -718,15 +754,29 @@ func testSwitchSendHtlcMapping(t *testing.T, zeroConf, useAlias bool, alias,
718
754
if useAlias {
719
755
outgoingSCID = alias
720
756
}
757
+ if successOrFailureOption == UnknownChannel {
758
+ outgoingSCID = lnwire.ShortChannelID {
759
+ BlockHeight : 123 ,
760
+ TxIndex : 123 ,
761
+ TxPosition : 123 ,
762
+ }
763
+ }
721
764
722
765
// Send the HTLC and assert that we don't get an error.
723
766
htlc := & lnwire.UpdateAddHTLC {
724
767
PaymentHash : rhash ,
725
768
Amount : 1 ,
726
769
}
727
-
728
770
err = s .SendHTLC (outgoingSCID , 0 , htlc )
729
- require .NoError (t , err )
771
+
772
+ switch successOrFailureOption {
773
+ case Success :
774
+ require .NoError (t , err )
775
+ case PeerOffline :
776
+ require .EqualError (t , err , "TemporaryChannelFailure" )
777
+ case UnknownChannel :
778
+ require .EqualError (t , err , "UnknownNextPeer" )
779
+ }
730
780
}
731
781
732
782
// TestSwitchUpdateScid verifies that zero-conf and non-zero-conf
0 commit comments