Skip to content

Commit

Permalink
pytest: fix flake in test_fetchinvoice
Browse files Browse the repository at this point in the history
On my local machine it can run into ratelimiting, because I miscounted the fetchinvoice
calls.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jul 18, 2024
1 parent 6bf41f4 commit 73e5d9a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4511,14 +4511,14 @@ def test_fetchinvoice(node_factory, bitcoind):
assert l1.rpc.call('decode', [inv1['invoice']])['invoice_amount_msat'] == 3
l1.rpc.pay(inv1['invoice'])

# We've done 4 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

# More than ~5x expected is rejected as absurd (it's actually a divide test,
# which means we need 15 here, not 11).
with pytest.raises(RpcError, match="Remote node sent failure message.*Amount vastly exceeds 2msat"):
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'amount_msat': 15})

# We've done 4 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

# Underpay is rejected.
with pytest.raises(RpcError, match="Remote node sent failure message.*Amount must be at least 2msat"):
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'amount_msat': 1})
Expand All @@ -4537,15 +4537,15 @@ def test_fetchinvoice(node_factory, bitcoind):
'description': 'single-use test',
'single_use': True})['bolt12']

# We've done 3 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

inv1 = l1.rpc.call('fetchinvoice', {'offer': offer2})
inv2 = l1.rpc.call('fetchinvoice', {'offer': offer2})
assert inv1 != inv2
assert 'next_period' not in inv1
assert 'next_period' not in inv2

# We've done 4 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

l1.rpc.pay(inv1['invoice'])

# We can't pay the other one now.
Expand All @@ -4564,6 +4564,9 @@ def test_fetchinvoice(node_factory, bitcoind):
offerusd = l3.rpc.call('offer', {'amount': '10.05USD',
'description': 'USD test'})['bolt12']

# We've done 3 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

inv = l1.rpc.call('fetchinvoice', {'offer': offerusd})
assert inv['changes']['amount_msat'] == Millisatoshi(int(10.05 * 5000))

Expand All @@ -4579,7 +4582,7 @@ def test_fetchinvoice(node_factory, bitcoind):
l4.rpc.connect(l3.info['id'], 'localhost', l3.port)
l4.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})

# We've done 4 onion calls: sleep now to avoid hitting ratelimit!
# We've done 3 onion calls: sleep now to avoid hitting ratelimit!
time.sleep(1)

# If we remove plugin, it can no longer give us an invoice.
Expand Down

0 comments on commit 73e5d9a

Please sign in to comment.