Example #1
0
def test_get_paths_via_debug_endpoint_empty_routes(
        api_url: str, addresses: List[Address],
        token_network_model: TokenNetwork):
    # `last_failed_requests` is a module variable, so it might have entries
    # from tests that ran earlier.
    last_failed_requests.clear()
    hex_addrs = [to_checksum_address(addr) for addr in addresses]
    token_network_address = to_checksum_address(token_network_model.address)

    response = requests.post(
        api_url + f"/v1/{token_network_address}/paths",
        json={
            "from": hex_addrs[0],
            "to": hex_addrs[5],
            "value": 10,
            "max_paths": DEFAULT_MAX_PATHS,
        },
    )
    assert response.status_code == 404

    # test that requests with no routes found are returned as well
    url_debug_incl_impossible_route = (
        api_url +
        f"/v1/_debug/routes/{token_network_address}/{hex_addrs[0]}/{hex_addrs[5]}"
    )
    response_debug_incl_impossible_route = requests.get(
        url_debug_incl_impossible_route)
    assert response_debug_incl_impossible_route.status_code == 200
    request_count = response_debug_incl_impossible_route.json(
    )["request_count"]
    assert request_count == 1

    response = requests.post(
        api_url + f"/v1/{token_network_address}/paths",
        json={
            "from": hex_addrs[0],
            "to": hex_addrs[6],
            "value": 1e10,
            "max_paths": DEFAULT_MAX_PATHS,
        },
    )
    assert response.status_code == 404

    # test that requests with no routes found are returned as well
    # regression test for https://github.com/raiden-network/raiden/issues/5421
    url_debug_incl_impossible_route = (
        api_url +
        f"/v1/_debug/routes/{token_network_address}/{hex_addrs[0]}/{hex_addrs[6]}"
    )
    response_debug_incl_impossible_route = requests.get(
        url_debug_incl_impossible_route)
    assert response_debug_incl_impossible_route.status_code == 200
    request_count = response_debug_incl_impossible_route.json(
    )["request_count"]
    assert request_count == 1
Example #2
0
def test_get_paths_via_debug_endpoint_a(api_url: str, addresses: List[Address],
                                        token_network_model: TokenNetwork):  # pylint: disable=too-many-locals
    # `last_failed_requests` is a module variable, so it might have entries
    # from tests that ran earlier.
    last_failed_requests.clear()
    hex_addrs = [to_checksum_address(addr) for addr in addresses]
    token_network_address = to_checksum_address(token_network_model.address)

    # Make two requests, so we can test the `request_count` as well
    for _ in range(2):
        response = requests.post(
            api_url + f"/v1/{token_network_address}/paths",
            json={
                "from": hex_addrs[0],
                "to": hex_addrs[2],
                "value": 10,
                "max_paths": DEFAULT_MAX_PATHS,
            },
        )
        assert response.status_code == 200
        paths = response.json()["result"]
        assert len(paths) == 1
        assert paths == [{
            "path": [hex_addrs[0], hex_addrs[1], hex_addrs[2]],
            "estimated_fee": 0,
            "address_metadata": {
                hex_addrs[0]: get_address_metadata(hex_addrs[0]),
                hex_addrs[1]: get_address_metadata(hex_addrs[1]),
                hex_addrs[2]: get_address_metadata(hex_addrs[2]),
            },
        }]

    # now there must be a debug endpoint for that specific route
    url_debug = api_url + f"/v1/_debug/routes/{token_network_address}/{hex_addrs[0]}"
    response_debug = requests.get(url_debug)
    assert response_debug.status_code == 200
    request_count = response_debug.json()["request_count"]
    assert request_count == 2
    responses = response_debug.json()["responses"]
    assert responses == [
        {
            "source":
            hex_addrs[0],
            "target":
            hex_addrs[2],
            "routes": [{
                "path": [hex_addrs[0], hex_addrs[1], hex_addrs[2]],
                "estimated_fee": 0
            }],
        },
        {
            "source":
            hex_addrs[0],
            "target":
            hex_addrs[2],
            "routes": [{
                "path": [hex_addrs[0], hex_addrs[1], hex_addrs[2]],
                "estimated_fee": 0
            }],
        },
    ]

    # now there must be a debug endpoint for that specific route and that specific target
    url_debug_incl_requested_target = (
        api_url +
        f"/v1/_debug/routes/{token_network_address}/{hex_addrs[0]}/{hex_addrs[2]}"
    )
    response_debug_incl_target = requests.get(url_debug_incl_requested_target)
    assert response_debug_incl_target.status_code == 200
    request_count = response_debug_incl_target.json()["request_count"]
    assert request_count == 2
    responses = response_debug.json()["responses"]
    assert responses == [
        {
            "source":
            hex_addrs[0],
            "target":
            hex_addrs[2],
            "routes": [{
                "path": [hex_addrs[0], hex_addrs[1], hex_addrs[2]],
                "estimated_fee": 0
            }],
        },
        {
            "source":
            hex_addrs[0],
            "target":
            hex_addrs[2],
            "routes": [{
                "path": [hex_addrs[0], hex_addrs[1], hex_addrs[2]],
                "estimated_fee": 0
            }],
        },
    ]

    # when requesting info for a target that was no path requested for
    url_debug_incl_unrequested_target = (
        api_url +
        f"/v1/_debug/routes/{token_network_address}/{hex_addrs[0]}/{hex_addrs[3]}"
    )
    response_debug_incl_unrequested_target = requests.get(
        url_debug_incl_unrequested_target)
    assert response_debug_incl_unrequested_target.status_code == 200
    request_count = response_debug_incl_unrequested_target.json(
    )["request_count"]
    assert request_count == 0
    responses = response_debug_incl_unrequested_target.json()["responses"]
    assert responses == []