@@ -2096,6 +2096,61 @@ def test_funding_change(self):
2096
2096
assert outputs [0 ] > 8990000
2097
2097
assert outputs [2 ] == 10000000
2098
2098
2099
+ def test_funding_fail (self ):
2100
+ """Add some funds, fund a channel without enough funds"""
2101
+ # Previous runs with same bitcoind can leave funds!
2102
+ l1 = self .node_factory .get_node (random_hsm = True )
2103
+ max_locktime = 3 * 6 * 24
2104
+ l2 = self .node_factory .get_node (options = ['--locktime-blocks={}' .format (max_locktime + 1 )])
2105
+ l1 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .info ['port' ])
2106
+
2107
+ addr = l1 .rpc .newaddr ()['address' ]
2108
+ txid = l1 .bitcoin .rpc .sendtoaddress (addr , 0.01 )
2109
+ bitcoind .generate_block (1 )
2110
+
2111
+ # Wait for it to arrive.
2112
+ wait_for (lambda : len (l1 .rpc .listfunds ()['outputs' ]) > 0 )
2113
+
2114
+ # Fail because l1 dislikes l2's huge locktime.
2115
+ try :
2116
+ l1 .rpc .fundchannel (l2 .info ['id' ], 100000 )
2117
+ except ValueError as verr :
2118
+ str (verr ).index ('to_self_delay {} larger than {}'
2119
+ .format (max_locktime + 1 , max_locktime ))
2120
+ except Exception as err :
2121
+ self .fail ("Unexpected exception {}" .format (err ))
2122
+ else :
2123
+ self .fail ("huge locktime ignored?" )
2124
+
2125
+ # We don't have enough left to cover fees if we try to spend it all.
2126
+ try :
2127
+ l1 .rpc .fundchannel (l2 .info ['id' ], 1000000 )
2128
+ except ValueError as verr :
2129
+ str (verr ).index ('Cannot afford funding transaction' )
2130
+ except Exception as err :
2131
+ self .fail ("Unexpected exception {}" .format (err ))
2132
+ else :
2133
+ self .fail ("We somehow covered fees?" )
2134
+
2135
+ # Should still be connected.
2136
+ assert l1 .rpc .getpeers ()['peers' ][0 ]['connected' ]
2137
+ assert l2 .rpc .getpeers ()['peers' ][0 ]['connected' ]
2138
+
2139
+ # Restart l2 without ridiculous locktime.
2140
+ l2 .daemon .proc .terminate ()
2141
+
2142
+ l2 .daemon .cmd_line .remove ('--locktime-blocks={}' .format (max_locktime + 1 ))
2143
+
2144
+ # Wait for l1 to notice
2145
+ wait_for (lambda : len (l1 .rpc .getpeers ()['peers' ]) == 0 )
2146
+
2147
+ # Now restart l2, reconnect.
2148
+ l2 .daemon .start ()
2149
+ l1 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .info ['port' ])
2150
+
2151
+ # This works.
2152
+ l1 .rpc .fundchannel (l2 .info ['id' ], int (0.01 * 10 ** 8 / 2 ))
2153
+
2099
2154
def test_addfunds_from_block (self ):
2100
2155
"""Send funds to the daemon without telling it explicitly
2101
2156
"""
0 commit comments