|
1 | 1 | use crate::tests::test_utils::expect_event;
|
2 |
| -use crate::{Builder, Config, Event}; |
| 2 | +use crate::{Builder, Config, Error, Event}; |
3 | 3 |
|
4 | 4 | use bitcoin::{Address, Amount};
|
5 | 5 | use bitcoind::bitcoincore_rpc::RpcApi;
|
@@ -88,14 +88,16 @@ where
|
88 | 88 | fn premine_and_distribute_funds(addrs: Vec<Address>, amount: Amount) {
|
89 | 89 | PREMINE.get_or_init(|| {
|
90 | 90 | generate_blocks_and_wait(101);
|
91 |
| - for addr in addrs { |
92 |
| - get_bitcoind() |
93 |
| - .client |
94 |
| - .send_to_address(&addr, amount, None, None, None, None, None, None) |
95 |
| - .unwrap(); |
96 |
| - } |
97 |
| - generate_blocks_and_wait(1); |
98 | 91 | });
|
| 92 | + |
| 93 | + for addr in addrs { |
| 94 | + get_bitcoind() |
| 95 | + .client |
| 96 | + .send_to_address(&addr, amount, None, None, None, None, None, None) |
| 97 | + .unwrap(); |
| 98 | + } |
| 99 | + |
| 100 | + generate_blocks_and_wait(1); |
99 | 101 | }
|
100 | 102 |
|
101 | 103 | fn rand_config() -> Config {
|
@@ -199,3 +201,32 @@ fn channel_full_cycle() {
|
199 | 201 | node_b.stop().unwrap();
|
200 | 202 | println!("\nB stopped");
|
201 | 203 | }
|
| 204 | + |
| 205 | +#[test] |
| 206 | +fn channel_open_fails_when_funds_insufficient() { |
| 207 | + println!("== Node A =="); |
| 208 | + let config_a = rand_config(); |
| 209 | + let node_a = Builder::from_config(config_a).build(); |
| 210 | + node_a.start().unwrap(); |
| 211 | + let addr_a = node_a.new_funding_address().unwrap(); |
| 212 | + |
| 213 | + println!("\n== Node B =="); |
| 214 | + let config_b = rand_config(); |
| 215 | + let node_b = Builder::from_config(config_b).build(); |
| 216 | + node_b.start().unwrap(); |
| 217 | + let addr_b = node_b.new_funding_address().unwrap(); |
| 218 | + |
| 219 | + premine_and_distribute_funds(vec![addr_a, addr_b], Amount::from_sat(100000)); |
| 220 | + node_a.sync_wallets().unwrap(); |
| 221 | + node_b.sync_wallets().unwrap(); |
| 222 | + assert_eq!(node_a.on_chain_balance().unwrap().get_spendable(), 100000); |
| 223 | + assert_eq!(node_b.on_chain_balance().unwrap().get_spendable(), 100000); |
| 224 | + |
| 225 | + println!("\nA -- connect_open_channel -> B"); |
| 226 | + let node_b_addr = |
| 227 | + format!("{}@{}", node_b.node_id().unwrap(), node_b.listening_address().unwrap()); |
| 228 | + assert_eq!( |
| 229 | + Err(Error::FundsInsufficient), |
| 230 | + node_a.connect_open_channel(&node_b_addr, 120000, true) |
| 231 | + ); |
| 232 | +} |
0 commit comments