@@ -3,6 +3,7 @@ package lnwire
3
3
import (
4
4
"bytes"
5
5
crand "crypto/rand"
6
+ "encoding/base64"
6
7
"encoding/binary"
7
8
"encoding/hex"
8
9
"fmt"
@@ -1660,6 +1661,83 @@ func TestLightningWireProtocol(t *testing.T) {
1660
1661
ChanUpdateDisableOutgoing
1661
1662
}
1662
1663
1664
+ v [0 ] = reflect .ValueOf (req )
1665
+ },
1666
+ MsgNodeAnnouncement2 : func (v []reflect.Value , r * rand.Rand ) {
1667
+ var req NodeAnnouncement2
1668
+
1669
+ req .ExtraSignedFields = ExtraSignedFields (
1670
+ randSignedRangeRecords (t , r ),
1671
+ )
1672
+ req .Signature .Val = testSchnorrSig
1673
+
1674
+ req .NodeID .Val = randRawKey (t )
1675
+ req .BlockHeight .Val = r .Uint32 ()
1676
+ req .Features .Val = * randRawFeatureVector (r )
1677
+
1678
+ // Sometimes set the colour field.
1679
+ if r .Int31 ()% 2 == 0 {
1680
+ color := tlv .ZeroRecordT [tlv.TlvType1 , Color ]()
1681
+ color .Val = Color {
1682
+ R : uint8 (r .Int31 ()),
1683
+ G : uint8 (r .Int31 ()),
1684
+ B : uint8 (r .Int31 ()),
1685
+ }
1686
+ req .Color = tlv .SomeRecordT (color )
1687
+ }
1688
+
1689
+ n := r .Intn (33 )
1690
+ b := make ([]byte , n )
1691
+ _ , err := rand .Read (b )
1692
+ require .NoError (t , err )
1693
+ if n > 0 {
1694
+ alias := []byte (
1695
+ base64 .StdEncoding .EncodeToString (b ),
1696
+ )
1697
+ if len (alias ) > 32 {
1698
+ alias = alias [:32 ]
1699
+ }
1700
+
1701
+ aliasRec := tlv .ZeroRecordT [
1702
+ tlv.TlvType3 , []byte ,
1703
+ ]()
1704
+ aliasRec .Val = alias
1705
+ }
1706
+
1707
+ // Sometimes add some ipv4 addrs.
1708
+ if r .Int31 ()% 2 == 0 {
1709
+ ipv4Addr , err := randTCP4Addr (r )
1710
+ require .NoError (t , err )
1711
+
1712
+ ipv4AddrRecord := tlv .ZeroRecordT [
1713
+ tlv.TlvType5 , IPV4Addrs ,
1714
+ ]()
1715
+ ipv4AddrRecord .Val = IPV4Addrs {ipv4Addr }
1716
+ req .IPV4Addrs = tlv .SomeRecordT (ipv4AddrRecord )
1717
+ }
1718
+ // Sometimes add some ipv6 addrs.
1719
+ if r .Int31 ()% 2 == 0 {
1720
+ ipv6Addr , err := randTCP6Addr (r )
1721
+ require .NoError (t , err )
1722
+
1723
+ ipv6AddrRecord := tlv .ZeroRecordT [
1724
+ tlv.TlvType7 , IPV6Addrs ,
1725
+ ]()
1726
+ ipv6AddrRecord .Val = IPV6Addrs {ipv6Addr }
1727
+ req .IPV6Addrs = tlv .SomeRecordT (ipv6AddrRecord )
1728
+ }
1729
+ // Sometimes add some torv3 addrs.
1730
+ if r .Int31 ()% 2 == 0 {
1731
+ torAddr , err := randV3OnionAddr (r )
1732
+ require .NoError (t , err )
1733
+
1734
+ torAddrRecord := tlv .ZeroRecordT [
1735
+ tlv.TlvType9 , TorV3Addrs ,
1736
+ ]()
1737
+ torAddrRecord .Val = TorV3Addrs {torAddr }
1738
+ req .TorV3Addrs = tlv .SomeRecordT (torAddrRecord )
1739
+ }
1740
+
1663
1741
v [0 ] = reflect .ValueOf (req )
1664
1742
},
1665
1743
}
@@ -1902,12 +1980,19 @@ func TestLightningWireProtocol(t *testing.T) {
1902
1980
return mainScenario (& m )
1903
1981
},
1904
1982
},
1983
+
1905
1984
{
1906
1985
msgType : MsgChannelUpdate2 ,
1907
1986
scenario : func (m ChannelUpdate2 ) bool {
1908
1987
return mainScenario (& m )
1909
1988
},
1910
1989
},
1990
+ {
1991
+ msgType : MsgNodeAnnouncement2 ,
1992
+ scenario : func (m NodeAnnouncement2 ) bool {
1993
+ return mainScenario (& m )
1994
+ },
1995
+ },
1911
1996
}
1912
1997
for _ , test := range tests {
1913
1998
t .Run (test .msgType .String (), func (t * testing.T ) {
0 commit comments