@@ -44,21 +44,36 @@ class LightningMessageCodecsSpec extends FunSuite {
4444 def publicKey (fill : Byte ) = PrivateKey (ByteVector .fill(32 )(fill)).publicKey
4545
4646 test(" encode/decode init message" ) {
47+ val chainHash1 = ByteVector32 (hex " 0101010101010101010101010101010101010101010101010101010101010101 " )
48+ val chainHash2 = ByteVector32 (hex " 0202020202020202020202020202020202020202020202020202020202020202 " )
4749 val testCases = Seq (
48- (hex " 0000 0000 " , hex " " , hex " 0000 0000 " ), // no features
49- (hex " 0000 0002088a " , hex " 088a " , hex " 0000 0002088a " ), // no global features
50- (hex " 00020200 0000 " , hex " 0200 " , hex " 0000 00020200 " ), // no local features
51- (hex " 00020200 0002088a " , hex " 0a8a " , hex " 0000 00020a8a " ), // local and global - no conflict - same size
52- (hex " 00020200 0003020002 " , hex " 020202 " , hex " 0000 0003020202 " ), // local and global - no conflict - different sizes
53- (hex " 00020a02 0002088a " , hex " 0a8a " , hex " 0000 00020a8a " ), // local and global - conflict - same size
54- (hex " 00022200 000302aaa2 " , hex " 02aaa2 " , hex " 0000 000302aaa2 " ) // local and global - conflict - different sizes
50+ (hex " 0000 0000 " , hex " " , Nil , true , None ), // no features
51+ (hex " 0000 0002088a " , hex " 088a " , Nil , true , None ), // no global features
52+ (hex " 00020200 0000 " , hex " 0200 " , Nil , true , Some (hex " 0000 00020200 " )), // no local features
53+ (hex " 00020200 0002088a " , hex " 0a8a " , Nil , true , Some (hex " 0000 00020a8a " )), // local and global - no conflict - same size
54+ (hex " 00020200 0003020002 " , hex " 020202 " , Nil , true , Some (hex " 0000 0003020202 " )), // local and global - no conflict - different sizes
55+ (hex " 00020a02 0002088a " , hex " 0a8a " , Nil , true , Some (hex " 0000 00020a8a " )), // local and global - conflict - same size
56+ (hex " 00022200 000302aaa2 " , hex " 02aaa2 " , Nil , true , Some (hex " 0000 000302aaa2 " )), // local and global - conflict - different sizes
57+ (hex " 0000 0002088a 03012a05022aa2 " , hex " 088a " , Nil , true , None ), // unknown odd records
58+ (hex " 0000 0002088a 03012a04022aa2 " , hex " 088a " , Nil , false , None ), // unknown even records
59+ (hex " 0000 0002088a 0120010101010101010101010101010101010101010101010101010101010101 " , hex " 088a " , Nil , false , None ), // invalid tlv stream
60+ (hex " 0000 0002088a 01200101010101010101010101010101010101010101010101010101010101010101 " , hex " 088a " , List (chainHash1), true , None ), // single network
61+ (hex " 0000 0002088a 014001010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202 " , hex " 088a " , List (chainHash1, chainHash2), true , None ), // multiple networks
62+ (hex " 0000 0002088a 0120010101010101010101010101010101010101010101010101010101010101010103012a " , hex " 088a " , List (chainHash1), true , None ), // network and unknown odd records
63+ (hex " 0000 0002088a 0120010101010101010101010101010101010101010101010101010101010101010102012a " , hex " 088a " , Nil , false , None ) // network and unknown even records
5564 )
5665
57- for ((bin, features, encoded) <- testCases) {
58- val init = initCodec.decode(bin.bits).require.value
59- assert(init.features === features)
60- assert(initCodec.encode(init).require.bytes === encoded)
61- assert(initCodec.decode(encoded.bits).require.value === init)
66+ for ((bin, features, networks, valid, encodedOverride) <- testCases) {
67+ if (valid) {
68+ val init = initCodec.decode(bin.bits).require.value
69+ assert(init.features === features)
70+ assert(init.networks === networks)
71+ val encoded = initCodec.encode(init).require
72+ assert(encoded.bytes === encodedOverride.getOrElse(bin))
73+ assert(initCodec.decode(encoded).require.value === init)
74+ } else {
75+ assert(initCodec.decode(bin.bits).isFailure)
76+ }
6277 }
6378 }
6479
0 commit comments