예제 #1
0
async def test_server_version(protocol, writer, method):
    params = ["obelisk 42", [SERVER_PROTO_MIN, SERVER_PROTO_MAX]]
    expect = {"result": [f"obelisk {VERSION}", SERVER_PROTO_MAX]}
    data = await protocol.server_version(writer, {"params": params})
    assert_equal(data["result"], expect["result"])

    params = ["obelisk", "0.0"]
    expect = JsonRPCError.protonotsupported()
    data = await protocol.server_version(writer, {"params": params})
    assert_equal(data, expect)

    params = ["obelisk"]
    expect = JsonRPCError.invalidparams()
    data = await protocol.server_version(writer, {"params": params})
    assert_equal(data, expect)
예제 #2
0
    async def server_version(self, writer, query):  # pylint: disable=W0613
        """Method: server.version
        Identify the client to the server and negotiate the protocol version.
        """
        if "params" not in query or len(query["params"]) != 2:
            return JsonRPCError.invalidparams()

        client_ver = query["params"][1]

        if isinstance(client_ver, list):
            client_min, client_max = client_ver[0], client_ver[1]
        else:
            client_min = client_max = client_ver

        version = min(client_max, SERVER_PROTO_MAX)

        if version < max(client_min, SERVER_PROTO_MIN):
            return JsonRPCError.protonotsupported()

        return {"result": [f"obelisk {VERSION}", version]}