Skip to content

Commit be5c51c

Browse files
committed
Filter for the initiator for received payment events
[ci integration]
1 parent 666fc84 commit be5c51c

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
Changelog
33
=========
44

5+
56
* :feature:`2287` Internal events now have timestamps.
67
* :feature:`2307` Matrix discovery rooms now are decentralized, aliased and shared by all servers in the federation
78
* :bug:`2461` Always return payment received events irrespective of the target parameter.
9+
* :bug:`2461` For received payments events filter based on the initiator.
810
* :feature:`2252` Adds payment history page to the webui.
911
* :bug:`2367` Token network selection dropdown will not filter out not connected networks.
1012
* :bug:`2453` Connection manager will no longer be stuck if there are no available channel partners

raiden/api/python.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@
4242
def event_filter_for_payments(
4343
event: architecture.Event,
4444
token_network_identifier: typing.TokenNetworkID = None,
45-
target_address: typing.Address = None,
45+
partner_address: typing.Address = None,
4646
) -> bool:
4747
"""Filters out non payment history related events
4848
4949
- If no other args are given, all payment related events match
5050
- If a token network identifier is given then only payment events for that match
51-
- If a target is also given then if the event is a payment sent event and the
52-
target matches it's returned. If it's a payment received it's always returned.
51+
- If a partner is also given then if the event is a payment sent event and the
52+
target matches it's returned. If it's a payment received and the initiator matches
53+
then it's returned.
5354
"""
5455
is_matching_event = (
5556
isinstance(event, EVENTS_PAYMENT_HISTORY_RELATED) and
@@ -64,11 +65,18 @@ def event_filter_for_payments(
6465
sent_and_target_matches = (
6566
isinstance(event, (EventPaymentSentFailed, EventPaymentSentSuccess)) and
6667
(
67-
target_address is None or
68-
event.target == target_address
68+
partner_address is None or
69+
event.target == partner_address
6970
)
7071
)
71-
return sent_and_target_matches or isinstance(event, (EventPaymentReceivedSuccess))
72+
received_and_initiator_matches = (
73+
isinstance(event, (EventPaymentSentFailed, EventPaymentReceivedSuccess)) and
74+
(
75+
partner_address is None or
76+
event.initiator == partner_address
77+
)
78+
)
79+
return sent_and_target_matches or received_and_initiator_matches
7280

7381

7482
class RaidenAPI:
@@ -698,7 +706,7 @@ def get_raiden_events_payment_history_with_timestamps(
698706
) if event_filter_for_payments(
699707
event=event.wrapped_event,
700708
token_network_identifier=token_network_identifier,
701-
target_address=target_address,
709+
partner_address=target_address,
702710
)
703711
]
704712

raiden/tests/integration/api/test_restapi.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ def test_payment_events_endpoints(test_api_server, raiden_network, token_address
12571257
identifier1 = 42
12581258
token_address = token_addresses[0]
12591259

1260+
app0_address = app0.raiden.address
12601261
target1_address = app1.raiden.address
12611262
target2_address = app2.raiden.address
12621263

@@ -1512,13 +1513,17 @@ def test_payment_events_endpoints(test_api_server, raiden_network, token_address
15121513
response = request.send().response
15131514
assert_proper_response(response, HTTPStatus.OK)
15141515
response = response.json()
1515-
assert must_have_events(
1516+
assert must_have_event(
15161517
response,
15171518
{
15181519
'event': 'EventPaymentSentSuccess',
15191520
'identifier': identifier3,
15201521
'target': to_checksum_address(target2_address),
1521-
}, {
1522+
},
1523+
)
1524+
assert not must_have_event(
1525+
response,
1526+
{
15221527
'event': 'EventPaymentReceivedSuccess',
15231528
'identifier': identifier1,
15241529
},
@@ -1534,20 +1539,46 @@ def test_payment_events_endpoints(test_api_server, raiden_network, token_address
15341539
response = request.send().response
15351540
assert_proper_response(response, HTTPStatus.OK)
15361541
response = response.json()
1537-
assert must_have_event(
1542+
assert len(response) == 0
1543+
# test endpoint for token and partner for target2
1544+
request = grequests.get(
1545+
api_url_for(
1546+
app2_server,
1547+
'token_target_paymentresource',
1548+
token_address=token_address,
1549+
target_address=app0_address,
1550+
),
1551+
)
1552+
response = request.send().response
1553+
assert_proper_response(response, HTTPStatus.OK)
1554+
response = response.json()
1555+
assert must_have_events(
1556+
response,
1557+
{
1558+
'event': 'EventPaymentReceivedSuccess',
1559+
'identifier': identifier2,
1560+
},
1561+
)
1562+
assert not must_have_event(
15381563
response,
15391564
{
15401565
'event': 'EventPaymentReceivedSuccess',
15411566
'identifier': identifier1,
15421567
},
15431568
)
1544-
# test endpoint for token and partner for target2
1569+
assert not must_have_event(
1570+
response,
1571+
{
1572+
'event': 'EventPaymentReceivedSuccess',
1573+
'identifier': identifier3,
1574+
},
1575+
)
15451576
request = grequests.get(
15461577
api_url_for(
15471578
app2_server,
15481579
'token_target_paymentresource',
15491580
token_address=token_address,
1550-
target_address=target2_address,
1581+
target_address=target1_address,
15511582
),
15521583
)
15531584
response = request.send().response
@@ -1556,13 +1587,17 @@ def test_payment_events_endpoints(test_api_server, raiden_network, token_address
15561587
assert must_have_events(
15571588
response,
15581589
{
1559-
'event': 'EventPaymentReceivedSuccess',
1560-
'identifier': identifier2,
1561-
}, {
15621590
'event': 'EventPaymentReceivedSuccess',
15631591
'identifier': identifier3,
15641592
},
15651593
)
1594+
assert not must_have_event(
1595+
response,
1596+
{
1597+
'event': 'EventPaymentReceivedSuccess',
1598+
'identifier': identifier2,
1599+
},
1600+
)
15661601
assert not must_have_event(
15671602
response,
15681603
{

0 commit comments

Comments
 (0)