From: Matt Corallo Date: Wed, 23 Jan 2019 22:06:38 +0000 (-0500) Subject: Fix indentation in a few new tests X-Git-Tag: v0.0.12~237^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d69fb5f58df5f5833563c997fd84df8d42cc1c7d;p=rust-lightning Fix indentation in a few new tests --- diff --git a/src/ln/functional_tests.rs b/src/ln/functional_tests.rs index d4c2afb7c..1e6f99d43 100644 --- a/src/ln/functional_tests.rs +++ b/src/ln/functional_tests.rs @@ -4567,63 +4567,63 @@ fn test_onion_failure() { #[test] #[should_panic] fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on its own as we are catching a panic - let nodes = create_network(2); - //Force duplicate channel ids - for node in nodes.iter() { - *node.keys_manager.override_channel_id_priv.lock().unwrap() = Some([0; 32]); - } - - // BOLT #2 spec: Sending node must ensure temporary_channel_id is unique from any other channel ID with the same peer. - let channel_value_satoshis=10000; - let push_msat=10001; - nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).unwrap(); - let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel).unwrap(); - - //Create a second channel with a channel_id collision - assert!(nodes[0].node.create_channel(nodes[0].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); + let nodes = create_network(2); + //Force duplicate channel ids + for node in nodes.iter() { + *node.keys_manager.override_channel_id_priv.lock().unwrap() = Some([0; 32]); + } + + // BOLT #2 spec: Sending node must ensure temporary_channel_id is unique from any other channel ID with the same peer. + let channel_value_satoshis=10000; + let push_msat=10001; + nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).unwrap(); + let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel).unwrap(); + + //Create a second channel with a channel_id collision + assert!(nodes[0].node.create_channel(nodes[0].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); } #[test] fn bolt2_open_channel_sending_node_checks_part2() { - let nodes = create_network(2); - - // BOLT #2 spec: Sending node must set funding_satoshis to less than 2^24 satoshis - let channel_value_satoshis=2^24; - let push_msat=10001; - assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); - - // BOLT #2 spec: Sending node must set push_msat to equal or less than 1000 * funding_satoshis - let channel_value_satoshis=10000; - // Test when push_msat is equal to 1000 * funding_satoshis. - let push_msat=1000*channel_value_satoshis+1; - assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); - - // BOLT #2 spec: Sending node must set set channel_reserve_satoshis greater than or equal to dust_limit_satoshis - let channel_value_satoshis=10000; - let push_msat=10001; - assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_ok()); //Create a valid channel - let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - assert!(node0_to_1_send_open_channel.channel_reserve_satoshis>=node0_to_1_send_open_channel.dust_limit_satoshis); - - // BOLT #2 spec: Sending node must set undefined bits in channel_flags to 0 - // Only the least-significant bit of channel_flags is currently defined resulting in channel_flags only having one of two possible states 0 or 1 - assert!(node0_to_1_send_open_channel.channel_flags<=1); - - // BOLT #2 spec: Sending node should set to_self_delay sufficient to ensure the sender can irreversibly spend a commitment transaction output, in case of misbehaviour by the receiver. - assert!(BREAKDOWN_TIMEOUT>0); - assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT); - - // BOLT #2 spec: Sending node must ensure the chain_hash value identifies the chain it wishes to open the channel within. - let chain_hash=genesis_block(Network::Testnet).header.bitcoin_hash(); - assert_eq!(node0_to_1_send_open_channel.chain_hash,chain_hash); - - // BOLT #2 spec: Sending node must set funding_pubkey, revocation_basepoint, htlc_basepoint, payment_basepoint, and delayed_payment_basepoint to valid DER-encoded, compressed, secp256k1 pubkeys. - assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.funding_pubkey.serialize()).is_ok()); - assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.revocation_basepoint.serialize()).is_ok()); - assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.htlc_basepoint.serialize()).is_ok()); - assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_basepoint.serialize()).is_ok()); - assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.delayed_payment_basepoint.serialize()).is_ok()); + let nodes = create_network(2); + + // BOLT #2 spec: Sending node must set funding_satoshis to less than 2^24 satoshis + let channel_value_satoshis=2^24; + let push_msat=10001; + assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); + + // BOLT #2 spec: Sending node must set push_msat to equal or less than 1000 * funding_satoshis + let channel_value_satoshis=10000; + // Test when push_msat is equal to 1000 * funding_satoshis. + let push_msat=1000*channel_value_satoshis+1; + assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_err()); + + // BOLT #2 spec: Sending node must set set channel_reserve_satoshis greater than or equal to dust_limit_satoshis + let channel_value_satoshis=10000; + let push_msat=10001; + assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42).is_ok()); //Create a valid channel + let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); + assert!(node0_to_1_send_open_channel.channel_reserve_satoshis>=node0_to_1_send_open_channel.dust_limit_satoshis); + + // BOLT #2 spec: Sending node must set undefined bits in channel_flags to 0 + // Only the least-significant bit of channel_flags is currently defined resulting in channel_flags only having one of two possible states 0 or 1 + assert!(node0_to_1_send_open_channel.channel_flags<=1); + + // BOLT #2 spec: Sending node should set to_self_delay sufficient to ensure the sender can irreversibly spend a commitment transaction output, in case of misbehaviour by the receiver. + assert!(BREAKDOWN_TIMEOUT>0); + assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT); + + // BOLT #2 spec: Sending node must ensure the chain_hash value identifies the chain it wishes to open the channel within. + let chain_hash=genesis_block(Network::Testnet).header.bitcoin_hash(); + assert_eq!(node0_to_1_send_open_channel.chain_hash,chain_hash); + + // BOLT #2 spec: Sending node must set funding_pubkey, revocation_basepoint, htlc_basepoint, payment_basepoint, and delayed_payment_basepoint to valid DER-encoded, compressed, secp256k1 pubkeys. + assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.funding_pubkey.serialize()).is_ok()); + assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.revocation_basepoint.serialize()).is_ok()); + assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.htlc_basepoint.serialize()).is_ok()); + assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.payment_basepoint.serialize()).is_ok()); + assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.delayed_payment_basepoint.serialize()).is_ok()); } // BOLT 2 Requirements for the Sender when constructing and sending an update_add_htlc message.