Skip to content

Commit bb9b3b8

Browse files
Fernando Cezar Bernardellikonradkonrad
authored andcommitted
add documentation for static path
1 parent 573fc4f commit bb9b3b8

File tree

2 files changed

+118
-20
lines changed

2 files changed

+118
-20
lines changed

docs/rest_api.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,12 +784,30 @@ Besides you can query all payments that you sent or received.
784784

785785
{
786786
"amount": "200",
787-
"identifier": "42"
787+
"identifier": "42",
788+
"paths": [
789+
{
790+
"route": ["0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8", "0x61C808D82A3Ac53231750daDc13c777b59310bD9"],
791+
"address_metadata": {
792+
"0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8": {
793+
"user_id": "@0xea674fdde714fd979de3edf0f56aa9716b898ec8:localhost:8502",
794+
"capabilities": "mxc://raiden.network/cap?Receive=1&Mediate=1&Delivery=1&webRTC=1&toDevice=1&immutableMetadata=1",
795+
"displayname": "0xdf714485248a7d83f29e059622004acbb8a6b8a09c1506c304c2748e4e941cf769e864764ef028b31da525280d35d5ab87ee196dc738bc0f8de81ca3355a0c111b"
796+
},
797+
"0x61C808D82A3Ac53231750daDc13c777b59310bD9": {
798+
"user_id": "@0x61c808d82a3ac53231750dadc13c777b59310bd9:localhost:8502",
799+
"capabilities": "mxc://raiden.network/cap?Receive=1&Mediate=1&Delivery=1&webRTC=1&toDevice=1&immutableMetadata=1",
800+
"displayname": "0x56682a1fecb4df0ce8e0e3aa9a0eaae4a6bc1a6265284f3fffbb1423e018122838353e6930c6000892e94f305b97c726a8e74c27dcce98adda9340f93555f5bb1c"
801+
}
802+
}
803+
}
804+
]
788805
}
789806

790807
:reqjson string amount: Amount to be sent to the target
791808
:reqjson string identifier: Identifier of the payment (optional)
792809
:reqjson string lock_timeout: lock timeout, in blocks, to be used with the payment. Default is 2 * channel's reveal_timeout, Value must be greater than channel's reveal_timeout (optional)
810+
:reqjson string path: static route to the target node (optional)
793811

794812

795813
**Example Response**:
@@ -813,7 +831,7 @@ Besides you can query all payments that you sent or received.
813831
:statuscode 400: The provided json is in some way malformed
814832
:statuscode 402: The payment can't start due to insufficient balance
815833
:statuscode 404: The given token and / or target addresses are not valid EIP55-encoded Ethereum addresses
816-
:statuscode 409: The address or the amount is invalid, or there is no path to the target, or the identifier is already in use for a different payment.
834+
:statuscode 409: The address or the amount is invalid, or there is no path to the target, or the identifier is already in use for a different payment, or the static path sent is not usable.
817835
:statuscode 500: Internal Raiden node error
818836
:statuscode 503: The API is currently unavailable, e. g. because the Raiden node is still in the initial sync or shutting down.
819837

raiden/tests/integration/api/rest/test_payments.py

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,19 @@ def test_api_payments_without_pfs(
212212
token_address=to_checksum_address(token_address),
213213
target_address=to_checksum_address(target_address),
214214
),
215-
json={"amount": "1"},
215+
json={
216+
"amount": str(amount),
217+
"paths": [
218+
{
219+
"route": [to_checksum_address(our_address), to_checksum_address(app1.address)],
220+
"address_metadata": {
221+
to_checksum_address(our_address): our_metadata,
222+
to_checksum_address(app1.address): app1.transport.address_metadata,
223+
},
224+
}
225+
],
226+
},
216227
)
217-
with watch_for_unlock_failures(*raiden_network):
218-
response = request.send().response
219-
assert_proper_response(response)
220-
json_response = get_json_response(response)
221-
assert_payment_secret_and_hash(json_response, payment)
222228

223229
# Test that trying out a payment with an amount higher than what is available
224230
# returns an error
@@ -230,23 +236,97 @@ def test_api_payments_without_pfs(
230236
token_address=to_checksum_address(token_address),
231237
target_address=to_checksum_address(target_address),
232238
),
233-
json={"amount": str(deposit)},
239+
json={
240+
"amount": str(deposit),
241+
"identifier": str(identifier),
242+
"paths": [
243+
{
244+
"route": [to_checksum_address(our_address), to_checksum_address(app1.address)],
245+
"address_metadata": {
246+
to_checksum_address(our_address): our_metadata,
247+
to_checksum_address(app1.address): app1.transport.address_metadata,
248+
},
249+
}
250+
],
251+
},
234252
)
235253
response = request.send().response
236254
assert_proper_response(response, status_code=HTTPStatus.CONFLICT)
237255

238-
# Test that querying the internal events resource works
239-
limit = 5
240-
request = grequests.get(
241-
api_url_for(
242-
api_server_test_instance, "raideninternaleventsresource", limit=limit, offset=0
256+
257+
@raise_on_failure
258+
@pytest.mark.parametrize("number_of_nodes", [2])
259+
@pytest.mark.parametrize("enable_rest_api", [True])
260+
def test_api_payments_without_pfs_failure(
261+
api_server_test_instance: APIServer,
262+
raiden_network: List[RaidenService],
263+
token_addresses,
264+
) -> None:
265+
app0, app1 = raiden_network
266+
amount = 100
267+
identifier = 42
268+
token_address = token_addresses[0]
269+
target_address = app1.address
270+
271+
our_address = api_server_test_instance.rest_api.raiden_api.address
272+
our_metadata = api_server_test_instance.rest_api.raiden_api.raiden.transport.address_metadata
273+
274+
def send_request(paths):
275+
request = grequests.post(
276+
api_url_for(
277+
api_server_test_instance,
278+
"token_target_paymentresource",
279+
token_address=to_checksum_address(token_address),
280+
target_address=to_checksum_address(target_address),
281+
),
282+
json={"amount": str(amount), "identifier": str(identifier), "paths": paths},
243283
)
244-
)
245-
response = request.send().response
246-
assert_proper_response(response)
247-
events = response.json()
248-
assert len(events) == limit
249-
assert all("TimestampedEvent" in event for event in events)
284+
285+
return request.send().response
286+
287+
# No route to target
288+
paths = [
289+
{
290+
"route": [to_checksum_address(our_address), to_checksum_address(app0.address)],
291+
"address_metadata": {
292+
to_checksum_address(our_address): our_metadata,
293+
to_checksum_address(app1.address): app1.transport.address_metadata,
294+
},
295+
}
296+
]
297+
298+
response = send_request(paths)
299+
assert_proper_response(response, status_code=HTTPStatus.CONFLICT)
300+
301+
# Path keys are invalid
302+
paths = [
303+
{
304+
"fake_route": [
305+
to_checksum_address(our_address),
306+
to_checksum_address(app0.address),
307+
],
308+
"fake_address_metadata": {
309+
to_checksum_address(our_address): our_metadata,
310+
to_checksum_address(app1.address): app1.transport.address_metadata,
311+
},
312+
}
313+
]
314+
response = send_request(paths)
315+
assert_proper_response(response, status_code=HTTPStatus.BAD_REQUEST)
316+
317+
# Bad data types
318+
paths = [
319+
{
320+
"route": ["fake_app0", "fake_app1"], # type: ignore
321+
"address_metadata": {
322+
"fake_app0": our_metadata, # type: ignore
323+
"fake_app1": app1.transport.address_metadata, # type: ignore
324+
},
325+
}
326+
]
327+
328+
response = send_request(paths)
329+
assert_proper_response(response, status_code=HTTPStatus.BAD_REQUEST)
250330

251331

252332
@raise_on_failure

0 commit comments

Comments
 (0)