Skip to content

Commit

Permalink
pytest: deactivate shadow routing for some tests that use 'pay'
Browse files Browse the repository at this point in the history
So that we can assert payment values
  • Loading branch information
darosior committed Nov 7, 2019
1 parent db00602 commit 608d868
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
8 changes: 4 additions & 4 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def test_htlc_sig_persistence(node_factory, bitcoind, executor):
assert len(l1.rpc.listfunds()['outputs']) == 3


@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_htlc_out_timeout(node_factory, bitcoind, executor):
"""Test that we drop onchain if the peer doesn't time out HTLC"""

Expand All @@ -328,7 +328,7 @@ def test_htlc_out_timeout(node_factory, bitcoind, executor):
inv = l2.rpc.invoice(amt, 'test_htlc_out_timeout', 'desc')['bolt11']
assert only_one(l2.rpc.listinvoices('test_htlc_out_timeout')['invoices'])['status'] == 'unpaid'

executor.submit(l1.rpc.pay, inv)
executor.submit(l1.rpc.dev_pay, inv, use_shadow=False)

# l1 will disconnect, and not reconnect.
l1.daemon.wait_for_log('dev_disconnect: @WIRE_REVOKE_AND_ACK')
Expand Down Expand Up @@ -373,7 +373,7 @@ def test_htlc_out_timeout(node_factory, bitcoind, executor):
l2.daemon.wait_for_log('onchaind complete, forgetting peer')


@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_htlc_in_timeout(node_factory, bitcoind, executor):
"""Test that we drop onchain if the peer doesn't accept fulfilled HTLC"""

Expand All @@ -395,7 +395,7 @@ def test_htlc_in_timeout(node_factory, bitcoind, executor):
inv = l2.rpc.invoice(amt, 'test_htlc_in_timeout', 'desc')['bolt11']
assert only_one(l2.rpc.listinvoices('test_htlc_in_timeout')['invoices'])['status'] == 'unpaid'

executor.submit(l1.rpc.pay, inv)
executor.submit(l1.rpc.dev_pay, inv, use_shadow=False)

# l1 will disconnect and not reconnect.
l1.daemon.wait_for_log('dev_disconnect: -WIRE_REVOKE_AND_ACK')
Expand Down
51 changes: 29 additions & 22 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import unittest


@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_pay(node_factory):
l1, l2 = node_factory.line_graph(2)

inv = l2.rpc.invoice(123000, 'test_pay', 'description')['bolt11']
before = int(time.time())
details = l1.rpc.pay(inv)
details = l1.rpc.dev_pay(inv, use_shadow=False)
after = int(time.time())
preimage = details['payment_preimage']
assert details['status'] == 'complete'
Expand All @@ -36,7 +37,7 @@ def test_pay(node_factory):
assert invoice['status'] == 'paid' and invoice['paid_at'] >= before and invoice['paid_at'] <= after

# Repeat payments are NOPs (if valid): we can hand null.
l1.rpc.pay(inv)
l1.rpc.dev_pay(inv, use_shadow=False)
# This won't work: can't provide an amount (even if correct!)
with pytest.raises(RpcError):
l1.rpc.pay(inv, 123000)
Expand All @@ -54,7 +55,7 @@ def test_pay(node_factory):
# Must provide an amount!
with pytest.raises(RpcError):
l1.rpc.pay(inv2)
l1.rpc.pay(inv2, random.randint(1000, 999999))
l1.rpc.dev_pay(inv2, random.randint(1000, 999999), use_shadow=False)

# Should see 6 completed payments
assert len(l1.rpc.listsendpays()['payments']) == 6
Expand All @@ -64,6 +65,7 @@ def test_pay(node_factory):
assert len(payments) == 1 and payments[0]['payment_preimage'] == preimage


@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_pay_amounts(node_factory):
l1, l2 = node_factory.line_graph(2)
inv = l2.rpc.invoice(Millisatoshi("123sat"), 'test_pay_amounts', 'description')['bolt11']
Expand All @@ -73,13 +75,14 @@ def test_pay_amounts(node_factory):
assert isinstance(invoice['amount_msat'], Millisatoshi)
assert invoice['amount_msat'] == Millisatoshi(123000)

l1.rpc.pay(inv)
l1.rpc.dev_pay(inv, use_shadow=False)

invoice = only_one(l2.rpc.listinvoices('test_pay_amounts')['invoices'])
assert isinstance(invoice['amount_received_msat'], Millisatoshi)
assert invoice['amount_received_msat'] >= Millisatoshi(123000)


@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_pay_limits(node_factory):
"""Test that we enforce fee max percentage and max delay"""
l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
Expand Down Expand Up @@ -120,7 +123,8 @@ def test_pay_limits(node_factory):
assert status[2]['strategy'].startswith("Trying route hint")

# This works, because fee is less than exemptfee.
l1.rpc.call('pay', {'bolt11': inv['bolt11'], 'msatoshi': 100000, 'maxfeepercent': 0.0001, 'exemptfee': 2000})
l1.rpc.dev_pay(inv['bolt11'], msatoshi=100000, maxfeepercent=0.0001,
exemptfee=2000, use_shadow=False)
status = l1.rpc.call('paystatus', {'bolt11': inv['bolt11']})['pay'][2]['attempts']
assert len(status) == 1
assert status[0]['strategy'] == "Initial attempt"
Expand Down Expand Up @@ -287,22 +291,23 @@ def test_pay_get_error_with_update(node_factory):
l1.daemon.wait_for_log(r'Received channel_update for channel {}/. now DISABLED'.format(chanid2))


@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_pay_optional_args(node_factory):
l1, l2 = node_factory.line_graph(2)

inv1 = l2.rpc.invoice(123000, 'test_pay', 'desc')['bolt11']
l1.rpc.pay(inv1, label='desc')
l1.rpc.dev_pay(inv1, label='desc', use_shadow=False)
payment1 = l1.rpc.listsendpays(inv1)['payments']
assert len(payment1) and payment1[0]['msatoshi'] == 123000
assert payment1[0]['label'] == 'desc'

inv2 = l2.rpc.invoice(321000, 'test_pay2', 'description')['bolt11']
l1.rpc.pay(inv2, riskfactor=5.0)
l1.rpc.dev_pay(inv2, riskfactor=5.0, use_shadow=False)
payment2 = l1.rpc.listsendpays(inv2)['payments']
assert len(payment2) == 1 and payment2[0]['msatoshi'] == 321000

anyinv = l2.rpc.invoice('any', 'any_pay', 'desc')['bolt11']
l1.rpc.pay(anyinv, label='desc', msatoshi='500')
l1.rpc.dev_pay(anyinv, label='desc', msatoshi='500', use_shadow=False)
payment3 = l1.rpc.listsendpays(anyinv)['payments']
assert len(payment3) == 1 and payment3[0]['msatoshi'] == 500
assert payment3[0]['label'] == 'desc'
Expand All @@ -311,7 +316,7 @@ def test_pay_optional_args(node_factory):
assert len(l1.rpc.listsendpays()['payments']) == 3


@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_payment_success_persistence(node_factory, bitcoind, executor):
# Start two nodes and open a channel.. die during payment.
# Feerates identical so we don't get gratuitous commit to update them
Expand All @@ -327,7 +332,7 @@ def test_payment_success_persistence(node_factory, bitcoind, executor):
inv1 = l2.rpc.invoice(1000, 'inv1', 'inv1')

# Fire off a pay request, it'll get interrupted by a restart
executor.submit(l1.rpc.pay, inv1['bolt11'])
executor.submit(l1.rpc.dev_pay, inv1['bolt11'], use_shadow=False)

l1.daemon.wait_for_log(r'dev_disconnect: \+WIRE_COMMITMENT_SIGNED')

Expand All @@ -351,7 +356,8 @@ def test_payment_success_persistence(node_factory, bitcoind, executor):
l1.wait_channel_active(chanid)

# A duplicate should succeed immediately (nop) and return correct preimage.
preimage = l1.rpc.pay(inv1['bolt11'])['payment_preimage']
preimage = l1.rpc.dev_pay(inv1['bolt11'],
use_shadow=False)['payment_preimage']
assert l1.rpc.dev_rhash(preimage)['rhash'] == inv1['payment_hash']


Expand Down Expand Up @@ -1600,7 +1606,7 @@ def listpays_nofail(b11):
fut = executor.submit(listpays_nofail, inv['bolt11'])

# Pay l1->l5 should succeed via straight line (eventually)
l1.rpc.pay(inv['bolt11'])
l1.rpc.dev_pay(inv['bolt11'], use_shadow=False)

# This should be OK.
fut.result()
Expand All @@ -1614,7 +1620,7 @@ def listpays_nofail(b11):
# It will try l1->l2->l3->l4->l5, which fails.
inv = l5.rpc.invoice(10**8, 'test_retry2', 'test_retry2')['bolt11']
with pytest.raises(RpcError, match=r'3 attempts'):
l1.rpc.pay(inv)
l1.rpc.dev_pay(inv, use_shadow=False)


@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 otherwise gossip takes 5 minutes!")
Expand Down Expand Up @@ -1652,7 +1658,7 @@ def test_pay_routeboost(node_factory, bitcoind):

# Now we should be able to pay it.
start = time.time()
l1.rpc.pay(inv['bolt11'])
l1.rpc.dev_pay(inv['bolt11'], use_shadow=False)
end = time.time()

# Status should show all the gory details.
Expand Down Expand Up @@ -1700,7 +1706,7 @@ def test_pay_routeboost(node_factory, bitcoind):
'label': 'test_pay_routeboost2',
'description': 'test_pay_routeboost2',
'dev-routes': [routel3l4l5]})
l1.rpc.pay(inv['bolt11'])
l1.rpc.dev_pay(inv['bolt11'], use_shadow=False)
status = l1.rpc.call('paystatus', [inv['bolt11']])
assert len(only_one(status['pay'])['attempts']) == 2
assert 'failure' in only_one(status['pay'])['attempts'][0]
Expand All @@ -1722,7 +1728,8 @@ def test_pay_routeboost(node_factory, bitcoind):
'label': 'test_pay_routeboost5',
'description': 'test_pay_routeboost5',
'dev-routes': [routel3l4l5, routel3l5]})
l1.rpc.pay(inv['bolt11'], label="paying test_pay_routeboost5")
l1.rpc.dev_pay(inv['bolt11'], label="paying test_pay_routeboost5",
use_shadow=False)

status = l1.rpc.call('paystatus', [inv['bolt11']])
assert only_one(status['pay'])['bolt11'] == inv['bolt11']
Expand Down Expand Up @@ -1797,7 +1804,7 @@ def test_pay_direct(node_factory, bitcoind):
for i in range(8):
inv = l3.rpc.invoice(20000000, 'pay{}'.format(i), 'desc')['bolt11']

l0.rpc.pay(inv)
l0.rpc.dev_pay(inv, use_shadow=False)

# We should have gone the direct route, so
# l1->l2 channel msatoshi_to_us should not
Expand Down Expand Up @@ -1964,7 +1971,7 @@ def test_setchannelfee_state(node_factory, bitcoind):
bitcoind.generate_block(6)
l0.wait_for_route(l2)
inv = l2.rpc.invoice(100000, 'test_setchannelfee_state', 'desc')['bolt11']
result = l0.rpc.pay(inv)
result = l0.rpc.dev_pay(inv, use_shadow=False)
assert result['status'] == 'complete'
assert result['msatoshi_sent'] == 100042

Expand Down Expand Up @@ -2029,7 +2036,7 @@ def test_setchannelfee_routing(node_factory, bitcoind):

# do and check actual payment
inv = l3.rpc.invoice(4999999, 'test_setchannelfee_1', 'desc')['bolt11']
result = l1.rpc.pay(inv)
result = l1.rpc.dev_pay(inv, use_shadow=False)
assert result['status'] == 'complete'
assert result['msatoshi_sent'] == 5002020

Expand All @@ -2049,7 +2056,7 @@ def test_setchannelfee_routing(node_factory, bitcoind):

# do and check actual payment
inv = l3.rpc.invoice(4999999, 'test_setchannelfee_2', 'desc')['bolt11']
result = l1.rpc.pay(inv)
result = l1.rpc.dev_pay(inv, use_shadow=False)
assert result['status'] == 'complete'
assert result['msatoshi_sent'] == 5000049

Expand Down Expand Up @@ -2086,7 +2093,7 @@ def test_setchannelfee_zero(node_factory, bitcoind):

# do and check actual payment
inv = l3.rpc.invoice(4999999, 'test_setchannelfee_3', 'desc')['bolt11']
result = l1.rpc.pay(inv)
result = l1.rpc.dev_pay(inv, use_shadow=False)
assert result['status'] == 'complete'
assert result['msatoshi_sent'] == 4999999

Expand Down Expand Up @@ -2128,7 +2135,7 @@ def test_setchannelfee_restart(node_factory, bitcoind):
# l1 can make payment to l3 with custom fees being applied
# Note: BOLT #7 math works out to 2021 msat fees
inv = l3.rpc.invoice(4999999, 'test_setchannelfee_1', 'desc')['bolt11']
result = l1.rpc.pay(inv)
result = l1.rpc.dev_pay(inv, use_shadow=False)
assert result['status'] == 'complete'
assert result['msatoshi_sent'] == 5002020

Expand Down
5 changes: 3 additions & 2 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor):
], wait_for_announce=True)

i1 = l3.rpc.invoice(msatoshi=1000, label="direct", description="desc")['bolt11']
f1 = executor.submit(l1.rpc.pay, i1)
f1 = executor.submit(l1.rpc.dev_pay, i1, use_shadow=False)

l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')

Expand Down Expand Up @@ -575,6 +575,7 @@ def test_warning_notification(node_factory):
l1.daemon.wait_for_log('plugin-pretend_badlog.py log: Test warning notification\\(for broken event\\)')


@unittest.skipIf(not DEVELOPER, "needs to deactivate shadow routing")
def test_invoice_payment_notification(node_factory):
"""
Test the 'invoice_payment' notification
Expand All @@ -586,7 +587,7 @@ def test_invoice_payment_notification(node_factory):
preimage = '1' * 64
label = "a_descriptive_label"
inv1 = l2.rpc.invoice(msats, label, 'description', preimage=preimage)
l1.rpc.pay(inv1['bolt11'])
l1.rpc.dev_pay(inv1['bolt11'], use_shadow=False)

l2.daemon.wait_for_log(r"Received invoice_payment event for label {},"
" preimage {}, and amount of {}msat"
Expand Down

0 comments on commit 608d868

Please sign in to comment.