Skip to content

Commit

Permalink
Fix PFS metadata accessibility in test_max_locks_reached
Browse files Browse the repository at this point in the history
  • Loading branch information
ezdac authored and karlb committed Nov 11, 2021
1 parent 517f26b commit e29d8f5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
39 changes: 34 additions & 5 deletions raiden/tests/integration/transfer/test_mediatedtransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
wait_assert,
)
from raiden.transfer import views
from raiden.transfer.events import EventPaymentSentFailed
from raiden.transfer.events import EventPaymentSentFailed, EventPaymentSentSuccess
from raiden.transfer.mediated_transfer.events import SendSecretRequest
from raiden.transfer.mediated_transfer.initiator import calculate_fee_margin
from raiden.transfer.mediated_transfer.mediation_fee import FeeScheduleState
Expand Down Expand Up @@ -773,6 +773,21 @@ def test_max_locks_reached(raiden_network: List[RaidenService], token_addresses)
transfers can be started.
"""
app0, app1 = raiden_network
# Enable direct transfers without passing explicit routes by letting
# the PFS's know about the partner's metadata
app0.pfs_proxy.set_services( # type: ignore
(
app0,
app1,
)
)
app1.pfs_proxy.set_services( # type: ignore
(
app0,
app1,
)
)

token_address = token_addresses[0]
token_network_registry_address = app0.default_registry.address
token_network_address = views.get_token_network_address_by_token_address(
Expand All @@ -788,22 +803,30 @@ def test_max_locks_reached(raiden_network: List[RaidenService], token_addresses)
)
assert channel_state is not None

statuses = []
secrethashes = []

# Create `MAXIMUM_PENDING_TRANSFERS` unfinished payments
for i in range(MAXIMUM_PENDING_TRANSFERS):
secret = Secret(keccak(i))
secrethash = sha256_secrethash(secret)
secrethashes.append(secrethash)

# Send payment while holding SecretRequest message
hold_event_handler_app1.hold_secretreveal_for(secrethash=secrethash)
# Send payment while holding SecretReveal message
result = hold_event_handler_app1.hold_secretreveal_for(secrethash=secrethash)

app0.mediated_transfer_async(
# NOTE making a transfer without passing an explicit `route_states` only works for
# direct transfers and when the PFS-Proxies of both apps do return the correct metadata!
status = app0.mediated_transfer_async(
token_network_address=token_network_address,
amount=PaymentAmount(1),
target=TargetAddress(app1.address),
identifier=PaymentID(i),
secret=secret,
lock_timeout=channel_state.settle_timeout,
)
).payment_done
statuses.append(status)
result.wait()

channel_state = views.get_channelstate_for(
views.state_from_raiden(app0), token_network_registry_address, token_address, app1.address
Expand All @@ -828,3 +851,9 @@ def test_max_locks_reached(raiden_network: List[RaidenService], token_addresses)
result = failed_status.payment_done.value
assert isinstance(result, EventPaymentSentFailed)
assert result.reason == "You have no suitable channel to initiate this payment."

for secrethash in secrethashes:
hold_event_handler_app1.release_secretreveal_for(app1, secrethash=secrethash)
gevent.joinall(statuses, timeout=20, raise_error=True)
for status in statuses:
assert isinstance(status.value, EventPaymentSentSuccess)
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_init_with_fees_more_than_max_limit():
assert transition.new_state is None
assert isinstance(transition.events[0], EventPaymentSentFailed)
reason_msg = (
"none of the available routes could be used and at least one of them "
"None of the available routes could be used and at least one of them "
"exceeded the maximum fee limit "
"(see https://raiden-network.readthedocs.io/en/stable/using-raiden-on-mainnet/overview.html#frequently-asked-questions)" # noqa
)
Expand Down

0 comments on commit e29d8f5

Please sign in to comment.