Skip to content

Commit 0272dcd

Browse files
author
Antoine Riard
committed
Add bolt1 msgs serialization tests
1 parent 6ed496d commit 0272dcd

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

src/ln/msgs.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ impl_writeable_len_match!(NodeAnnouncement, {
13921392
mod tests {
13931393
use hex;
13941394
use ln::msgs;
1395-
use ln::msgs::{GlobalFeatures, OptionalField, OnionErrorPacket};
1395+
use ln::msgs::{GlobalFeatures, LocalFeatures, OptionalField, OnionErrorPacket};
13961396
use ln::channelmanager::{PaymentPreimage, PaymentHash};
13971397
use util::ser::Writeable;
13981398

@@ -1890,4 +1890,61 @@ mod tests {
18901890
let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202013413a7").unwrap();
18911891
assert_eq!(encoded_value, target_value);
18921892
}
1893+
1894+
fn do_encoding_init(unknown_global_bits: bool, initial_routing_sync: bool) {
1895+
let mut global = GlobalFeatures::new();
1896+
if unknown_global_bits {
1897+
global.flags = vec![0xFF, 0xFF];
1898+
}
1899+
let mut local = LocalFeatures::new();
1900+
if initial_routing_sync {
1901+
local.set_initial_routing_sync();
1902+
}
1903+
let init = msgs::Init {
1904+
global_features: global,
1905+
local_features: local,
1906+
};
1907+
let encoded_value = init.encode();
1908+
let mut target_value = Vec::new();
1909+
if unknown_global_bits {
1910+
target_value.append(&mut hex::decode("0002ffff").unwrap());
1911+
} else {
1912+
target_value.append(&mut hex::decode("0000").unwrap());
1913+
}
1914+
if initial_routing_sync {
1915+
target_value.append(&mut hex::decode("000108").unwrap());
1916+
} else {
1917+
target_value.append(&mut hex::decode("0000").unwrap());
1918+
}
1919+
assert_eq!(encoded_value, target_value);
1920+
}
1921+
1922+
#[test]
1923+
fn encoding_init() {
1924+
do_encoding_init(false, false);
1925+
do_encoding_init(true, false);
1926+
do_encoding_init(false, true);
1927+
do_encoding_init(true, true);
1928+
}
1929+
1930+
#[test]
1931+
fn encoding_error() {
1932+
let error = msgs::ErrorMessage {
1933+
channel_id: [2; 32],
1934+
data: String::from("rust-lightning"),
1935+
};
1936+
let encoded_value = error.encode();
1937+
let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000e727573742d6c696768746e696e67").unwrap();
1938+
assert_eq!(encoded_value, target_value);
1939+
}
1940+
1941+
#[test]
1942+
fn encoding_ping() {
1943+
//TODO
1944+
}
1945+
1946+
#[test]
1947+
fn encoding_pong() {
1948+
//TODO
1949+
}
18931950
}

0 commit comments

Comments
 (0)