@@ -2160,6 +2160,61 @@ def test_funding_change(self):
2160
2160
assert outputs [0 ] > 8990000
2161
2161
assert outputs [2 ] == 10000000
2162
2162
2163
+ def test_funding_fail (self ):
2164
+ """Add some funds, fund a channel without enough funds"""
2165
+ # Previous runs with same bitcoind can leave funds!
2166
+ l1 = self .node_factory .get_node (random_hsm = True )
2167
+ max_locktime = 3 * 6 * 24
2168
+ l2 = self .node_factory .get_node (options = ['--locktime-blocks={}' .format (max_locktime + 1 )])
2169
+ l1 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .info ['port' ])
2170
+
2171
+ addr = l1 .rpc .newaddr ()['address' ]
2172
+ txid = l1 .bitcoin .rpc .sendtoaddress (addr , 0.01 )
2173
+ bitcoind .generate_block (1 )
2174
+
2175
+ # Wait for it to arrive.
2176
+ wait_for (lambda : len (l1 .rpc .listfunds ()['outputs' ]) > 0 )
2177
+
2178
+ # Fail because l1 dislikes l2's huge locktime.
2179
+ try :
2180
+ l1 .rpc .fundchannel (l2 .info ['id' ], 100000 )
2181
+ except ValueError as verr :
2182
+ str (verr ).index ('to_self_delay {} larger than {}'
2183
+ .format (max_locktime + 1 , max_locktime ))
2184
+ except Exception as err :
2185
+ self .fail ("Unexpected exception {}" .format (err ))
2186
+ else :
2187
+ self .fail ("huge locktime ignored?" )
2188
+
2189
+ # We don't have enough left to cover fees if we try to spend it all.
2190
+ try :
2191
+ l1 .rpc .fundchannel (l2 .info ['id' ], 1000000 )
2192
+ except ValueError as verr :
2193
+ str (verr ).index ('Cannot afford funding transaction' )
2194
+ except Exception as err :
2195
+ self .fail ("Unexpected exception {}" .format (err ))
2196
+ else :
2197
+ self .fail ("We somehow covered fees?" )
2198
+
2199
+ # Should still be connected.
2200
+ assert l1 .rpc .getpeers ()['peers' ][0 ]['connected' ]
2201
+ assert l2 .rpc .getpeers ()['peers' ][0 ]['connected' ]
2202
+
2203
+ # Restart l2 without ridiculous locktime.
2204
+ l2 .daemon .proc .terminate ()
2205
+
2206
+ l2 .daemon .cmd_line .remove ('--locktime-blocks={}' .format (max_locktime + 1 ))
2207
+
2208
+ # Wait for l1 to notice
2209
+ wait_for (lambda : len (l1 .rpc .getpeers ()['peers' ]) == 0 )
2210
+
2211
+ # Now restart l2, reconnect.
2212
+ l2 .daemon .start ()
2213
+ l1 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .info ['port' ])
2214
+
2215
+ # This works.
2216
+ l1 .rpc .fundchannel (l2 .info ['id' ], int (0.01 * 10 ** 8 / 2 ))
2217
+
2163
2218
def test_addfunds_from_block (self ):
2164
2219
"""Send funds to the daemon without telling it explicitly
2165
2220
"""
0 commit comments