Skip to content

Commit

Permalink
pytest: test shadow routing in pay plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed Nov 4, 2019
1 parent cfd6af8 commit 21e98c9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,3 +2338,28 @@ def test_error_returns_blockheight(node_factory, bitcoind):
# * [`u32`:`height`]
assert (err.value.error['data']['raw_message']
== '400f{:016x}{:08x}'.format(100, bitcoind.rpc.getblockcount()))


@flaky
def test_shadow_routing(node_factory):
"""
Test the value randomization through shadow routing
Since there is a very low (0.5**10) probability that it fails we mark it
as flaky.
"""
# We need l3 for random walk
l1, l2, l3 = node_factory.line_graph(3)

amount = 10000
total_amount = 0
n_payments = 10
for i in range(n_payments):
inv = l2.rpc.invoice(amount, "{}".format(i), "test")["bolt11"]
total_amount += l1.rpc.pay(inv)["amount_msat"]

assert total_amount.millisatoshis > n_payments * amount
# Test that the added amount isn't absurd
assert total_amount.millisatoshis < (n_payments * amount) * (1 + 0.01)

# FIXME: Test cltv delta too ?

0 comments on commit 21e98c9

Please sign in to comment.