use rand::{thread_rng,Rng};
use std::cell::RefCell;
-use std::collections::HashMap;
-use std::default::Default;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::mem;
macro_rules! check_spends {
($tx: expr, $spends_tx: expr) => {
{
- let mut funding_tx_map = HashMap::new();
- let spends_tx = $spends_tx;
- funding_tx_map.insert(spends_tx.txid(), spends_tx);
- $tx.verify(&funding_tx_map).unwrap();
+ $tx.verify(|out_point| {
+ if out_point.txid == $spends_tx.txid() {
+ $spends_tx.output.get(out_point.vout as usize).cloned()
+ } else {
+ None
+ }
+ }).unwrap();
}
}
}
(our_payment_preimage, our_payment_hash)
}
-pub fn claim_payment_along_route(origin_node: &Node, expected_route: &[&Node], skip_last: bool, our_payment_preimage: PaymentPreimage) {
- assert!(expected_route.last().unwrap().node.claim_funds(our_payment_preimage));
+pub fn claim_payment_along_route(origin_node: &Node, expected_route: &[&Node], skip_last: bool, our_payment_preimage: PaymentPreimage, expected_amount: u64) {
+ assert!(expected_route.last().unwrap().node.claim_funds(our_payment_preimage, expected_amount));
check_added_monitors!(expected_route.last().unwrap(), 1);
let mut next_msgs: Option<(msgs::UpdateFulfillHTLC, msgs::CommitmentSigned)> = None;
}
}
-pub fn claim_payment(origin_node: &Node, expected_route: &[&Node], our_payment_preimage: PaymentPreimage) {
- claim_payment_along_route(origin_node, expected_route, false, our_payment_preimage);
+pub fn claim_payment(origin_node: &Node, expected_route: &[&Node], our_payment_preimage: PaymentPreimage, expected_amount: u64) {
+ claim_payment_along_route(origin_node, expected_route, false, our_payment_preimage, expected_amount);
}
pub const TEST_FINAL_CLTV: u32 = 32;
let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
match err {
- APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight"),
+ APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"),
_ => panic!("Unknown error variants"),
};
}
-pub fn send_payment(origin: &Node, expected_route: &[&Node], recv_value: u64) {
+pub fn send_payment(origin: &Node, expected_route: &[&Node], recv_value: u64, expected_value: u64) {
let our_payment_preimage = route_payment(&origin, expected_route, recv_value).0;
- claim_payment(&origin, expected_route, our_payment_preimage);
+ claim_payment(&origin, expected_route, our_payment_preimage, expected_value);
}
pub fn fail_payment_along_route(origin_node: &Node, expected_route: &[&Node], skip_last: bool, our_payment_hash: PaymentHash) {
let mut default_config = UserConfig::new();
default_config.channel_options.announced_channel = true;
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
- let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }).unwrap();
+ let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }, 0).unwrap();
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger));
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed: seed,
network_payment_count: payment_count.clone(),