MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_coin_movement_notices

Function test_coin_movement_notices

tests/test_plugin.py:1955–2066  ·  view source on GitHub ↗

Verify that channel coin movements are triggered correctly.

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1953@pytest.mark.openchannel('v1')
1954@pytest.mark.openchannel('v2')
1955def test_coin_movement_notices(node_factory, bitcoind, chainparams):
1956 """Verify that channel coin movements are triggered correctly. """
1957
1958 l1_l2_mvts = [
1959 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']},
1960 {'type': 'channel_mvt', 'credit_msat': 100001001, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '1001msat'},
1961 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['routed'], 'fees_msat': '501msat'},
1962 {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'},
1963 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000000, 'tags': ['invoice'], 'fees_msat': '0msat'},
1964 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 100001001, 'tags': ['channel_close']},
1965 ]
1966
1967 l2_l3_mvts = [
1968 {'type': 'chain_mvt', 'credit_msat': 1000000000, 'debit_msat': 0, 'tags': ['channel_open', 'opener']},
1969 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 100000000, 'tags': ['routed'], 'fees_msat': '1001msat'},
1970 {'type': 'channel_mvt', 'credit_msat': 50000501, 'debit_msat': 0, 'tags': ['routed'], 'fees_msat': '501msat'},
1971 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 950000501, 'tags': ['channel_close']},
1972 ]
1973
1974 l3_l2_mvts = [
1975 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 0, 'tags': ['channel_open']},
1976 {'type': 'channel_mvt', 'credit_msat': 100000000, 'debit_msat': 0, 'tags': ['invoice'], 'fees_msat': '0msat'},
1977 {'type': 'channel_mvt', 'credit_msat': 0, 'debit_msat': 50000501, 'tags': ['invoice'], 'fees_msat': '501msat'},
1978 {'type': 'chain_mvt', 'credit_msat': 0, 'debit_msat': 49999499, 'tags': ['channel_close']},
1979 ]
1980
1981 coin_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1982 l1, l2, l3 = node_factory.line_graph(3, opts=[
1983 {'may_reconnect': True},
1984 {'may_reconnect': True, 'plugin': coin_plugin},
1985 {'may_reconnect': True, 'plugin': coin_plugin},
1986 ], wait_for_announce=True)
1987
1988 mine_funding_to_announce(bitcoind, [l1, l2, l3])
1989 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4)
1990 amount = 10**8
1991
1992 inv = l3.rpc.invoice(amount, "first", "desc")
1993 payment_hash13 = inv['payment_hash']
1994 route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
1995
1996 # status: offered -> settled
1997 l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret'])
1998 l1.rpc.waitsendpay(payment_hash13)
1999
2000 # status: offered -> failed
2001 route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
2002 payment_hash13 = "f" * 64
2003 with pytest.raises(RpcError):
2004 l1.rpc.sendpay(route, payment_hash13, payment_secret=inv['payment_secret'])
2005 l1.rpc.waitsendpay(payment_hash13)
2006
2007 # go the other direction
2008 inv = l1.rpc.invoice(amount // 2, "first", "desc")
2009 payment_hash31 = inv['payment_hash']
2010 route = l3.rpc.getroute(l1.info['id'], amount // 2, 1)['route']
2011 l3.rpc.sendpay(route, payment_hash31, payment_secret=inv['payment_secret'])
2012 l3.rpc.waitsendpay(payment_hash31)

Callers

nothing calls this directly

Calls 15

mine_funding_to_announceFunction · 0.90
wait_forFunction · 0.90
first_channel_idFunction · 0.90
account_balanceFunction · 0.90
sync_blockheightFunction · 0.90
check_coin_movesFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
getrouteMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
restartMethod · 0.80

Tested by

no test coverage detected