@ -6,7 +6,7 @@ from flaky import flaky # noqa: F401
from pyln . client import RpcError
from utils import (
DEVELOPER , only_one , wait_for , sync_blockheight , VALGRIND , TIMEOUT ,
SLOW_MACHINE , COMPAT , expected_features
SLOW_MACHINE , expected_features
)
from bitcoin . core import CMutableTransaction , CMutableTxOut
@ -704,101 +704,6 @@ def test_shutdown_awaiting_lockin(node_factory, bitcoind):
wait_for ( lambda : l2 . rpc . listpeers ( ) [ ' peers ' ] == [ ] )
@unittest . skipIf ( not COMPAT , " needs COMPAT=1 " )
def test_deprecated_fundchannel_start ( node_factory , bitcoind ) :
""" Test the deprecated old-style:
fundchannel { id } { satoshi } { feerate } { announce }
"""
l1 , l2 = node_factory . get_nodes ( 2 , opts = [ { ' allow-deprecated-apis ' : True } , { } ] )
nodeid = l2 . info [ ' id ' ]
# New style(object type)
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , amount = 10 * * 6 , feerate = ' 2000perkw ' , announce = True )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , amount = 10 * * 6 , announce = True )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , amount = 10 * * 6 , feerate = ' 2000perkw ' )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , amount = 10 * * 6 )
# Array type
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid , 10 * * 6 , ' 2000perkw ' , True ] )
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid , 10 * * 6 , None , True ] )
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid , 10 * * 6 , ' slow ' ] )
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid , 10 * * 6 ] )
# No 'amount' nor 'satoshi'(array type)
with pytest . raises ( RpcError , match = r ' missing required parameter: amount ' ) :
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid ] )
with pytest . raises ( RpcError , match = r ' .*should be a satoshi amount, not.* ' ) :
l1 . rpc . call ( ' check ' , [ ' fundchannel_start ' , nodeid , ' 2000perkw ' ] )
# Old style(object type)
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , satoshi = 10 * * 6 , feerate = ' 2000perkw ' , announce = False )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , satoshi = 10 * * 6 , feerate = ' slow ' )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , satoshi = 10 * * 6 , announce = True )
l1 . rpc . check ( command_to_check = ' fundchannel_start ' , id = nodeid , satoshi = 10 * * 6 )
# For json object type when allow deprecated api, 'check' command can't find
# the error if we don't set 'amount' nor 'satoshi'.
l1 . rpc . connect ( nodeid , ' localhost ' , l2 . port )
# No 'amount' nor 'satoshi'(object type)
with pytest . raises ( RpcError , match = r ' Need set \' amount \' field ' ) :
l1 . rpc . call ( ' fundchannel_start ' , { ' id ' : nodeid , ' feerate ' : ' 2000perkw ' } )
@unittest . skipIf ( not COMPAT , " needs COMPAT=1 " )
def test_deprecated_fundchannel ( node_factory , bitcoind ) :
""" Test the deprecated old-style:
fundchannel { id } { satoshi } { feerate } { announce } { minconf } { utxos }
"""
l1 = node_factory . get_node ( options = { ' allow-deprecated-apis ' : True } )
# FIXME: Use 'check' command after libplugin(C language) supports 'check' mode for command
nodes = node_factory . get_nodes ( 8 )
amount = int ( 0.0005 * 10 * * 8 )
for n in nodes :
l1 . rpc . connect ( n . info [ ' id ' ] , ' localhost ' , n . port )
# Get 8 utxos
for i in range ( 8 ) :
l1 . fundwallet ( 10 * * 8 )
bitcoind . generate_block ( 1 )
sync_blockheight ( bitcoind , [ l1 ] )
wait_for ( lambda : len ( l1 . rpc . listfunds ( ) [ " outputs " ] ) == 8 )
# No 'amount' nor 'satoshi'(array type)
with pytest . raises ( RpcError , match = r ' missing required parameter: amount ' ) :
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 0 ] . info [ ' id ' ] ] )
with pytest . raises ( RpcError , match = r ' .* should be a satoshi amount, not .* ' ) :
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 0 ] . info [ ' id ' ] , ' slow ' ] )
def get_utxo ( node ) :
""" Get an unspent but confirmed output
"""
outputs = node . rpc . listfunds ( ) [ ' outputs ' ]
for o in outputs :
if o [ ' status ' ] == ' confirmed ' :
return " {} : {} " . format ( o [ ' txid ' ] , o [ ' output ' ] )
# Array type
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 0 ] . info [ ' id ' ] , amount , ' 2000perkw ' , False , 1 , [ get_utxo ( l1 ) ] ] )
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 1 ] . info [ ' id ' ] , amount , ' 2000perkw ' , False , None , [ get_utxo ( l1 ) ] ] )
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 2 ] . info [ ' id ' ] , amount , ' 2000perkw ' , None , None , [ get_utxo ( l1 ) ] ] )
l1 . rpc . call ( ' fundchannel ' , [ nodes [ 3 ] . info [ ' id ' ] , amount , ' 2000perkw ' , True , 1 ] )
# No 'amount' nor 'satoshi'(object type)
with pytest . raises ( RpcError , match = r ' Need set \' amount \' field ' ) :
l1 . rpc . call ( ' fundchannel ' , { ' id ' : nodes [ 4 ] . info [ ' id ' ] , ' feerate ' : ' 2000perkw ' } )
# Old style(object type)
l1 . rpc . call ( ' fundchannel ' , { ' id ' : nodes [ 4 ] . info [ ' id ' ] , ' satoshi ' : ' all ' , ' feerate ' : ' slow ' ,
' announce ' : True , ' minconf ' : 1 , ' utxos ' : [ get_utxo ( l1 ) ] } )
l1 . rpc . call ( ' fundchannel ' , { ' id ' : nodes [ 5 ] . info [ ' id ' ] , ' satoshi ' : ' all ' , ' feerate ' : ' slow ' , ' minconf ' : 1 } )
l1 . rpc . call ( ' fundchannel ' , { ' id ' : nodes [ 6 ] . info [ ' id ' ] , ' satoshi ' : ' all ' , ' feerate ' : ' slow ' } )
l1 . rpc . call ( ' fundchannel ' , { ' id ' : nodes [ 7 ] . info [ ' id ' ] , ' satoshi ' : ' all ' } )
def test_funding_change ( node_factory , bitcoind ) :
""" Add some funds, fund a channel, and make sure we remember the change
"""