+ do_encoding_open_channel(false, false, false);
+ do_encoding_open_channel(false, false, true);
+ do_encoding_open_channel(false, true, false);
+ do_encoding_open_channel(false, true, true);
+ do_encoding_open_channel(true, false, false);
+ do_encoding_open_channel(true, false, true);
+ do_encoding_open_channel(true, true, false);
+ do_encoding_open_channel(true, true, true);
+ }
+
+ fn do_encoding_open_channelv2(random_bit: bool, shutdown: bool, incl_chan_type: bool, require_confirmed_inputs: bool) {
+ let secp_ctx = Secp256k1::new();
+ let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
+ let (_, pubkey_2) = get_keys_from!("0202020202020202020202020202020202020202020202020202020202020202", secp_ctx);
+ let (_, pubkey_3) = get_keys_from!("0303030303030303030303030303030303030303030303030303030303030303", secp_ctx);
+ let (_, pubkey_4) = get_keys_from!("0404040404040404040404040404040404040404040404040404040404040404", secp_ctx);
+ let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
+ let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
+ let (_, pubkey_7) = get_keys_from!("0707070707070707070707070707070707070707070707070707070707070707", secp_ctx);
+ let open_channelv2 = msgs::OpenChannelV2 {
+ chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+ temporary_channel_id: [2; 32],
+ funding_feerate_sat_per_1000_weight: 821716,
+ commitment_feerate_sat_per_1000_weight: 821716,
+ funding_satoshis: 1311768467284833366,
+ dust_limit_satoshis: 3608586615801332854,
+ max_htlc_value_in_flight_msat: 8517154655701053848,
+ htlc_minimum_msat: 2316138423780173,
+ to_self_delay: 49340,
+ max_accepted_htlcs: 49340,
+ locktime: 305419896,
+ funding_pubkey: pubkey_1,
+ revocation_basepoint: pubkey_2,
+ payment_basepoint: pubkey_3,
+ delayed_payment_basepoint: pubkey_4,
+ htlc_basepoint: pubkey_5,
+ first_per_commitment_point: pubkey_6,
+ second_per_commitment_point: pubkey_7,
+ channel_flags: if random_bit { 1 << 5 } else { 0 },
+ shutdown_scriptpubkey: if shutdown { Some(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).script_pubkey()) } else { None },
+ channel_type: if incl_chan_type { Some(ChannelTypeFeatures::empty()) } else { None },
+ require_confirmed_inputs: if require_confirmed_inputs { Some(()) } else { None },
+ };
+ let encoded_value = open_channelv2.encode();
+ let mut target_value = Vec::new();
+ target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+ target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
+ target_value.append(&mut hex::decode("000c89d4").unwrap());
+ target_value.append(&mut hex::decode("000c89d4").unwrap());
+ target_value.append(&mut hex::decode("1234567890123456").unwrap());
+ target_value.append(&mut hex::decode("3214466870114476").unwrap());
+ target_value.append(&mut hex::decode("7633030896203198").unwrap());
+ target_value.append(&mut hex::decode("00083a840000034d").unwrap());
+ target_value.append(&mut hex::decode("c0bc").unwrap());
+ target_value.append(&mut hex::decode("c0bc").unwrap());
+ target_value.append(&mut hex::decode("12345678").unwrap());
+ target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap());
+ target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap());
+ target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap());
+ target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
+ target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap());
+ target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
+ target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap());
+
+ if random_bit {
+ target_value.append(&mut hex::decode("20").unwrap());
+ } else {
+ target_value.append(&mut hex::decode("00").unwrap());
+ }
+ if shutdown {
+ target_value.append(&mut hex::decode("001b").unwrap()); // Type 0 + Length 27
+ target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+ }
+ if incl_chan_type {
+ target_value.append(&mut hex::decode("0100").unwrap());
+ }
+ if require_confirmed_inputs {
+ target_value.append(&mut hex::decode("0200").unwrap());
+ }
+ assert_eq!(encoded_value, target_value);
+ }
+
+ #[test]
+ fn encoding_open_channelv2() {
+ do_encoding_open_channelv2(false, false, false, false);
+ do_encoding_open_channelv2(false, false, false, true);
+ do_encoding_open_channelv2(false, false, true, false);
+ do_encoding_open_channelv2(false, false, true, true);
+ do_encoding_open_channelv2(false, true, false, false);
+ do_encoding_open_channelv2(false, true, false, true);
+ do_encoding_open_channelv2(false, true, true, false);
+ do_encoding_open_channelv2(false, true, true, true);
+ do_encoding_open_channelv2(true, false, false, false);
+ do_encoding_open_channelv2(true, false, false, true);
+ do_encoding_open_channelv2(true, false, true, false);
+ do_encoding_open_channelv2(true, false, true, true);
+ do_encoding_open_channelv2(true, true, false, false);
+ do_encoding_open_channelv2(true, true, false, true);
+ do_encoding_open_channelv2(true, true, true, false);
+ do_encoding_open_channelv2(true, true, true, true);