Skip to content

Commit

Permalink
add documentation for static path
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cezar Bernardelli authored and konradkonrad committed Sep 15, 2021
1 parent 573fc4f commit bb9b3b8
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 20 deletions.
22 changes: 20 additions & 2 deletions docs/rest_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,30 @@ Besides you can query all payments that you sent or received.

{
"amount": "200",
"identifier": "42"
"identifier": "42",
"paths": [
{
"route": ["0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8", "0x61C808D82A3Ac53231750daDc13c777b59310bD9"],
"address_metadata": {
"0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8": {
"user_id": "@0xea674fdde714fd979de3edf0f56aa9716b898ec8:localhost:8502",
"capabilities": "mxc://raiden.network/cap?Receive=1&Mediate=1&Delivery=1&webRTC=1&toDevice=1&immutableMetadata=1",
"displayname": "0xdf714485248a7d83f29e059622004acbb8a6b8a09c1506c304c2748e4e941cf769e864764ef028b31da525280d35d5ab87ee196dc738bc0f8de81ca3355a0c111b"
},
"0x61C808D82A3Ac53231750daDc13c777b59310bD9": {
"user_id": "@0x61c808d82a3ac53231750dadc13c777b59310bd9:localhost:8502",
"capabilities": "mxc://raiden.network/cap?Receive=1&Mediate=1&Delivery=1&webRTC=1&toDevice=1&immutableMetadata=1",
"displayname": "0x56682a1fecb4df0ce8e0e3aa9a0eaae4a6bc1a6265284f3fffbb1423e018122838353e6930c6000892e94f305b97c726a8e74c27dcce98adda9340f93555f5bb1c"
}
}
}
]
}

:reqjson string amount: Amount to be sent to the target
:reqjson string identifier: Identifier of the payment (optional)
: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)
:reqjson string path: static route to the target node (optional)


**Example Response**:
Expand All @@ -813,7 +831,7 @@ Besides you can query all payments that you sent or received.
:statuscode 400: The provided json is in some way malformed
:statuscode 402: The payment can't start due to insufficient balance
:statuscode 404: The given token and / or target addresses are not valid EIP55-encoded Ethereum addresses
: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.
: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.
:statuscode 500: Internal Raiden node error
:statuscode 503: The API is currently unavailable, e. g. because the Raiden node is still in the initial sync or shutting down.

Expand Down
116 changes: 98 additions & 18 deletions raiden/tests/integration/api/rest/test_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,19 @@ def test_api_payments_without_pfs(
token_address=to_checksum_address(token_address),
target_address=to_checksum_address(target_address),
),
json={"amount": "1"},
json={
"amount": str(amount),
"paths": [
{
"route": [to_checksum_address(our_address), to_checksum_address(app1.address)],
"address_metadata": {
to_checksum_address(our_address): our_metadata,
to_checksum_address(app1.address): app1.transport.address_metadata,
},
}
],
},
)
with watch_for_unlock_failures(*raiden_network):
response = request.send().response
assert_proper_response(response)
json_response = get_json_response(response)
assert_payment_secret_and_hash(json_response, payment)

# Test that trying out a payment with an amount higher than what is available
# returns an error
Expand All @@ -230,23 +236,97 @@ def test_api_payments_without_pfs(
token_address=to_checksum_address(token_address),
target_address=to_checksum_address(target_address),
),
json={"amount": str(deposit)},
json={
"amount": str(deposit),
"identifier": str(identifier),
"paths": [
{
"route": [to_checksum_address(our_address), to_checksum_address(app1.address)],
"address_metadata": {
to_checksum_address(our_address): our_metadata,
to_checksum_address(app1.address): app1.transport.address_metadata,
},
}
],
},
)
response = request.send().response
assert_proper_response(response, status_code=HTTPStatus.CONFLICT)

# Test that querying the internal events resource works
limit = 5
request = grequests.get(
api_url_for(
api_server_test_instance, "raideninternaleventsresource", limit=limit, offset=0

@raise_on_failure
@pytest.mark.parametrize("number_of_nodes", [2])
@pytest.mark.parametrize("enable_rest_api", [True])
def test_api_payments_without_pfs_failure(
api_server_test_instance: APIServer,
raiden_network: List[RaidenService],
token_addresses,
) -> None:
app0, app1 = raiden_network
amount = 100
identifier = 42
token_address = token_addresses[0]
target_address = app1.address

our_address = api_server_test_instance.rest_api.raiden_api.address
our_metadata = api_server_test_instance.rest_api.raiden_api.raiden.transport.address_metadata

def send_request(paths):
request = grequests.post(
api_url_for(
api_server_test_instance,
"token_target_paymentresource",
token_address=to_checksum_address(token_address),
target_address=to_checksum_address(target_address),
),
json={"amount": str(amount), "identifier": str(identifier), "paths": paths},
)
)
response = request.send().response
assert_proper_response(response)
events = response.json()
assert len(events) == limit
assert all("TimestampedEvent" in event for event in events)

return request.send().response

# No route to target
paths = [
{
"route": [to_checksum_address(our_address), to_checksum_address(app0.address)],
"address_metadata": {
to_checksum_address(our_address): our_metadata,
to_checksum_address(app1.address): app1.transport.address_metadata,
},
}
]

response = send_request(paths)
assert_proper_response(response, status_code=HTTPStatus.CONFLICT)

# Path keys are invalid
paths = [
{
"fake_route": [
to_checksum_address(our_address),
to_checksum_address(app0.address),
],
"fake_address_metadata": {
to_checksum_address(our_address): our_metadata,
to_checksum_address(app1.address): app1.transport.address_metadata,
},
}
]
response = send_request(paths)
assert_proper_response(response, status_code=HTTPStatus.BAD_REQUEST)

# Bad data types
paths = [
{
"route": ["fake_app0", "fake_app1"], # type: ignore
"address_metadata": {
"fake_app0": our_metadata, # type: ignore
"fake_app1": app1.transport.address_metadata, # type: ignore
},
}
]

response = send_request(paths)
assert_proper_response(response, status_code=HTTPStatus.BAD_REQUEST)


@raise_on_failure
Expand Down

0 comments on commit bb9b3b8

Please sign in to comment.