Browse Source

coin moves tests: push_msat and the wallet withdrawal

Check that we account for push_msat and wallet withdrawal/deposits
correctly
nifty/pset-pre
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
1b5221cbf5
  1. 20
      tests/test_connection.py
  2. 47
      tests/test_misc.py

20
tests/test_connection.py

@ -6,7 +6,8 @@ from flaky import flaky # noqa: F401
from pyln.client import RpcError, Millisatoshi
from utils import (
DEVELOPER, only_one, wait_for, sync_blockheight, VALGRIND, TIMEOUT,
SLOW_MACHINE, expected_peer_features, expected_node_features
SLOW_MACHINE, expected_peer_features, expected_node_features,
check_coin_moves, first_channel_id, account_balance
)
from bitcoin.core import CMutableTransaction, CMutableTxOut
@ -821,7 +822,10 @@ def test_funding_toolarge(node_factory, bitcoind):
def test_funding_push(node_factory, bitcoind):
""" Try to push peer some sats """
l1 = node_factory.get_node()
# We track balances, to verify that accounting is ok.
coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
l1 = node_factory.get_node(options={'plugin': coin_mvt_plugin})
l2 = node_factory.get_node()
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -842,11 +846,23 @@ def test_funding_push(node_factory, bitcoind):
# This should work.
amount = amount - 1
l1.rpc.fundchannel(l2.info['id'], amount, push_msat=push_sat * 1000)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
funds = only_one(l1.rpc.listfunds()['channels'])
assert funds['channel_sat'] + push_sat == funds['channel_total_sat']
l1.daemon.wait_for_log('1 coins')
# we have to give the file write a second
time.sleep(1)
chanid = first_channel_id(l2, l1)
channel_mvts = [
{'type': 'chain_mvt', 'credit': 0, 'debit': 20000000, 'tag': 'pushed'},
{'type': 'chain_mvt', 'credit': 16777215000, 'debit': 0, 'tag': 'deposit'},
]
check_coin_moves(l1, chanid, channel_mvts)
assert account_balance(l1, chanid) == (amount - push_sat) * 1000
def test_funding_by_utxos(node_factory, bitcoind):
"""Fund a channel with specific utxos"""

47
tests/test_misc.py

@ -9,6 +9,9 @@ from pyln.testing.utils import (
DEVELOPER, TIMEOUT, VALGRIND, DEPRECATED_APIS, sync_blockheight, only_one,
wait_for, TailableProc, env
)
from utils import (
check_coin_moves, account_balance
)
from ephemeral_port_reserve import reserve
from utils import EXPERIMENTAL_FEATURES
@ -472,10 +475,14 @@ def test_bech32_funding(node_factory, chainparams):
assert only_one(fundingtx['vin'])['txid'] == res['wallettxid']
def test_withdraw(node_factory, bitcoind, chainparams):
def test_withdraw_misc(node_factory, bitcoind, chainparams):
# We track channel balances, to verify that accounting is ok.
coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
amount = 1000000
# Don't get any funds from previous runs.
l1 = node_factory.get_node(random_hsm=True)
l1 = node_factory.get_node(random_hsm=True,
options={'plugin': coin_mvt_plugin})
l2 = node_factory.get_node(random_hsm=True)
addr = l1.rpc.newaddr()['bech32']
@ -597,6 +604,42 @@ def test_withdraw(node_factory, bitcoind, chainparams):
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
l1.rpc.withdraw(waddr, 'all')
assert account_balance(l1, 'wallet') == 0
wallet_moves = [
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 2000000000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 1993730000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 2000000000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 6270000, 'tag': 'chain_fees'},
{'type': 'chain_mvt', 'credit': 1993730000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 1993730000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 2000000000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 6270000, 'tag': 'chain_fees'},
{'type': 'chain_mvt', 'credit': 1993730000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 1993730000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 2000000000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 6270000, 'tag': 'chain_fees'},
{'type': 'chain_mvt', 'credit': 1993730000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 1993370000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 2000000000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 6630000, 'tag': 'chain_fees'},
{'type': 'chain_mvt', 'credit': 1993370000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 11961030000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 13530000, 'tag': 'chain_fees'},
{'type': 'chain_mvt', 'credit': 11961030000, 'debit': 0, 'tag': 'deposit'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 11957378000, 'tag': 'withdrawal'},
{'type': 'chain_mvt', 'credit': 0, 'debit': 3652000, 'tag': 'chain_fees'},
]
check_coin_moves(l1, 'wallet', wallet_moves)
def test_minconf_withdraw(node_factory, bitcoind):
"""Issue 2518: ensure that ridiculous confirmation levels don't overflow

Loading…
Cancel
Save