//! nodes for functional tests.
use chain::Watch;
-use chain::chainmonitor::ChannelMonitor;
+use chain::channelmonitor::ChannelMonitor;
use chain::transaction::OutPoint;
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
use routing::router::{Route, get_route};
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, height: u32) {
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
- while node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height) {}
+ node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
node.node.block_connected(&block.header, &txdata, height);
}
}
}
+#[cfg(test)]
macro_rules! get_htlc_update_msgs {
($node: expr, $node_id: expr) => {
{
}
}
+#[cfg(test)]
macro_rules! get_feerate {
($node: expr, $channel_id: expr) => {
{
}
}
+#[cfg(test)]
macro_rules! get_local_commitment_txn {
($node: expr, $channel_id: expr) => {
{
}
}
+/// Check whether N channel monitor(s) have been added.
+#[macro_export]
macro_rules! check_added_monitors {
($node: expr, $count: expr) => {
{
macro_rules! check_spends {
($tx: expr, $($spends_txn: expr),*) => {
{
- $tx.verify(|out_point| {
+ let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| {
$(
if out_point.txid == $spends_txn.txid() {
return $spends_txn.output.get(out_point.vout as usize).cloned()
}
)*
None
- }).unwrap();
+ };
+ let mut total_value_in = 0;
+ for input in $tx.input.iter() {
+ total_value_in += get_output(&input.previous_output).unwrap().value;
+ }
+ let mut total_value_out = 0;
+ for output in $tx.output.iter() {
+ total_value_out += output.value;
+ }
+ let min_fee = ($tx.get_weight() as u64 + 3) / 4; // One sat per vbyte (ie per weight/4, rounded up)
+ // Input amount - output amount = fee, so check that out + min_fee is smaller than input
+ assert!(total_value_out + min_fee <= total_value_in);
+ $tx.verify(get_output).unwrap();
}
}
}
}
}
+/// Check that a channel's closing channel update has been broadcasted, and optionally
+/// check whether an error message event has occurred.
+#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {{
let events = $node.node.get_and_clear_pending_msg_events();
}}
}
+#[cfg(test)]
macro_rules! expect_payment_received {
($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => {
let events = $node.node.get_and_clear_pending_events();
}
}
+#[cfg(test)]
macro_rules! expect_payment_failed {
($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
let events = $node.node.get_and_clear_pending_events();
}
}
+#[cfg(test)]
macro_rules! get_channel_value_stat {
($node: expr, $channel_id: expr) => {{
let chan_lock = $node.node.channel_state.lock().unwrap();