diff --git a/etherlink/tezt/lib/evm_node.ml b/etherlink/tezt/lib/evm_node.ml index 20df3c5bb8899416bc0271270c0f169cec0f1691..9b38088696df085cfd30662558a6ded946f1032b 100644 --- a/etherlink/tezt/lib/evm_node.ml +++ b/etherlink/tezt/lib/evm_node.ml @@ -1342,7 +1342,7 @@ let rpc_endpoint_record ?(local = false) (evm_node : t) = else Runner.address evm_node.persistent_state.runner in let port = evm_node.persistent_state.rpc_port in - Endpoint.{host; scheme = "http"; port} + Endpoint.make ~host ~scheme:"http" ~port () let endpoint = rpc_endpoint ?local:None diff --git a/src/lib_octogram/tezos.ml b/src/lib_octogram/tezos.ml index 5f1365a8b3e50f9db4fd4445e125e1c589ef0a53..29044d42a3b4cfb7cd388d57f78d734d2e95b316 100644 --- a/src/lib_octogram/tezos.ml +++ b/src/lib_octogram/tezos.ml @@ -39,11 +39,11 @@ let positive_int_of_string level = let parse_endpoint str = match str =~*** rex {|^(https?)://(.*):(\d+)|} with | Some (scheme, host, port_str) -> - Endpoint.{host; scheme; port = int_of_string port_str} + Endpoint.make ~host ~scheme ~port:(int_of_string port_str) () | None -> ( match str =~** rex {|^(.*):(\d+)|} with | Some (host, port_str) -> - {host; scheme = "http"; port = int_of_string port_str} + Endpoint.make ~host ~scheme:"http" ~port:(int_of_string port_str) () | None -> raise (Invalid_argument "parse_endpoint")) type _ key += Octez_node_k : string -> Node.t key diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 1d1c42ce86fd9370c0e789d53735d6af065b3b17..7fecc632fe11d76ecc3a9d5733c55b2d1a211d5f 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -31,6 +31,10 @@ type endpoint = Node of Node.t | Foreign_endpoint of Endpoint.t type media_type = Json | Binary | Any +let rpc_path = function + | Node _ -> "" + | Foreign_endpoint fe -> Endpoint.rpc_path fe + let rpc_port = function | Node n -> Node.rpc_port n | Foreign_endpoint fe -> Endpoint.rpc_port fe @@ -188,7 +192,7 @@ let mode_to_endpoint = function Some endpoint let string_of_endpoint ?hostname e = - sf "%s://%s:%d" (scheme e) (address ?hostname e) (rpc_port e) + sf "%s://%s:%d%s" (scheme e) (address ?hostname e) (rpc_port e) (rpc_path e) (* [?endpoint] can be used to override the default node stored in the client. Mockup nodes do not use [--endpoint] at all: RPCs are mocked up. diff --git a/tezt/lib_tezos/dal_common.ml b/tezt/lib_tezos/dal_common.ml index 9fc4c420a3e433cee12ab201cb224404ccd76826..8be8381051614fee7b5a8ba8887473b859329dd1 100644 --- a/tezt/lib_tezos/dal_common.ml +++ b/tezt/lib_tezos/dal_common.ml @@ -707,12 +707,11 @@ module Helpers = struct | None -> store_slot ~slot_index (Either.Left dal_node) slot | Some runner -> let endpoint = - Endpoint. - { - host = runner.Runner.address; - scheme = "http"; - port = Dal_node.rpc_port dal_node; - } + Endpoint.make + ~host:runner.Runner.address + ~scheme:"http" + ~port:(Dal_node.rpc_port dal_node) + () in store_slot ~slot_index (Either.Right endpoint) slot diff --git a/tezt/lib_tezos/dal_node.ml b/tezt/lib_tezos/dal_node.ml index 918b90b05eff51d1cfe2cde159d91ca9713c91bb..a421d25f3eea57c19d69b546b9ca7d72ef5a4f53 100644 --- a/tezt/lib_tezos/dal_node.ml +++ b/tezt/lib_tezos/dal_node.ml @@ -398,7 +398,7 @@ let run ?(wait_ready = true) ?env ?event_level node = let as_rpc_endpoint (t : t) = let state = t.persistent_state in let scheme = "http" in - Endpoint.{scheme; host = state.rpc_host; port = state.rpc_port} + Endpoint.make ~scheme ~host:state.rpc_host ~port:state.rpc_port () let runner (t : t) = t.persistent_state.runner diff --git a/tezt/lib_tezos/endpoint.ml b/tezt/lib_tezos/endpoint.ml index e1a0c99a50e2bfb2b68385d756ee0647518a66ec..2efc210a975584413032efe483bc726e828e64b9 100644 --- a/tezt/lib_tezos/endpoint.ml +++ b/tezt/lib_tezos/endpoint.ml @@ -23,7 +23,9 @@ (* *) (*****************************************************************************) -type t = {host : string; scheme : string; port : int} +type t = {host : string; scheme : string; port : int; path : string} + +let make ?(path = "") ~host ~scheme ~port () = {host; scheme; port; path} let rpc_host {host; _} = host @@ -31,7 +33,9 @@ let rpc_port {port; _} = port let rpc_scheme {scheme; _} = scheme -let as_string {scheme; host; port} = - Printf.sprintf "%s://%s:%d" scheme host port +let rpc_path {path; _} = path + +let as_string {scheme; host; port; path} = + Printf.sprintf "%s://%s:%d%s" scheme host port path let to_uri v = as_string v |> Uri.of_string diff --git a/tezt/lib_tezos/endpoint.mli b/tezt/lib_tezos/endpoint.mli index 88d6d7e02f4e8200d06f7a3ba21d7ba0cd6d16ad..2e7b005816b3c8ceba3ef7284220fcd804857d31 100644 --- a/tezt/lib_tezos/endpoint.mli +++ b/tezt/lib_tezos/endpoint.mli @@ -25,7 +25,9 @@ (** RPC endpoints. *) -type t = {host : string; scheme : string; port : int} +type t = {host : string; scheme : string; port : int; path : string} + +val make : ?path:string -> host:string -> scheme:string -> port:int -> unit -> t val rpc_host : t -> string @@ -33,6 +35,8 @@ val rpc_port : t -> int val rpc_scheme : t -> string +val rpc_path : t -> string + (** Encode the given endpoint as a string value. *) val as_string : t -> string diff --git a/tezt/lib_tezos/injector.ml b/tezt/lib_tezos/injector.ml index f8bb967e3221af5b89dd31016623c64d17410d31..2aa0777edca311bf00263462a6308aa058ff4657 100644 --- a/tezt/lib_tezos/injector.ml +++ b/tezt/lib_tezos/injector.ml @@ -54,7 +54,7 @@ let rpc_port injector = Option.get @@ Uri.port injector.persistent_state.uri let as_rpc_endpoint (t : t) = let host = rpc_host t in let port = rpc_port t in - Endpoint.{scheme = "http"; host; port} + Endpoint.make ~scheme:"http" ~host ~port () let data_dir injector = injector.persistent_state.data_dir diff --git a/tezt/lib_tezos/node.ml b/tezt/lib_tezos/node.ml index f73db210f17311ed04add5b4585dda883077da17..a9cb0d9531eb778929a4a5b89ec8aa55c48416ff 100644 --- a/tezt/lib_tezos/node.ml +++ b/tezt/lib_tezos/node.ml @@ -1136,7 +1136,7 @@ let as_rpc_endpoint ?(local = false) (t : t) = if local || Option.is_none t.persistent_state.runner then state.rpc_host else Runner.address t.persistent_state.runner in - Endpoint.{scheme; host; port = state.rpc_port} + Endpoint.make ~scheme ~host ~port:state.rpc_port () module RPC = struct module RPC_callers : RPC_core.CALLERS with type uri_provider := t = struct diff --git a/tezt/lib_tezos/sc_rollup_node.ml b/tezt/lib_tezos/sc_rollup_node.ml index 7c6bd5c8a2d068b01e7e3d283bd81ecc0708c4a2..30f49979163253de509027c5b81895ca57ebbca5 100644 --- a/tezt/lib_tezos/sc_rollup_node.ml +++ b/tezt/lib_tezos/sc_rollup_node.ml @@ -811,7 +811,7 @@ let import_snapshot ?(apply_unsafe_patches = false) ?(force = false) let as_rpc_endpoint (t : t) = let state = t.persistent_state in let scheme = "http" in - Endpoint.{scheme; host = state.rpc_host; port = state.rpc_port} + Endpoint.make ~scheme ~host:state.rpc_host ~port:state.rpc_port () let operators t = (t.persistent_state.default_operator, t.persistent_state.operators) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index baccf6458899f574959d70eeb50e203f3bda1a88..a2f9840f030ed82fcb5f99939feb0e180cd31c57 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -425,7 +425,7 @@ module Dal_reverse_proxy = struct rpc_port and never call Dal_node.run on the result. Since the DAL node never runs, it does not call it's L1 endpoint. *) - let l1_node_endpoint : Endpoint.t = {host = ""; scheme = ""; port = 0} in + let l1_node_endpoint = Endpoint.make ~host:"" ~scheme:"" ~port:0 () in let* dal_node = Dal_node.Agent.create_from_endpoint ~name:"bootstrap-dal-node" @@ -1098,7 +1098,7 @@ module Monitoring_app = struct (* Default to https default https port. *) match scheme with "https" -> 443 | "http" -> 80 | _ -> 443 in - Endpoint.{host; scheme; port} + Endpoint.make ~host ~scheme ~port () module Format_app = struct (* Helper for Slack App message format block-kit @@ -1147,7 +1147,7 @@ module Monitoring_app = struct let post_message ?ts ~slack_channel_id ~slack_bot_token data = let data = Format_app.make_payload ?ts ~slack_channel_id data in let slack_endpoint = - {Endpoint.scheme = "https"; host = "slack.com"; port = 443} + Endpoint.make ~scheme:"https" ~host:"slack.com" ~port:443 () in let rpc = RPC_core.make @@ -1199,7 +1199,7 @@ module Monitoring_app = struct (Uri.query uri) in let path = String.split_on_char '/' (Uri.path uri) in - let endpoint = Endpoint.{host; scheme; port} in + let endpoint = Endpoint.make ~host ~scheme ~port () in (`endpoint endpoint, `query query_string, `path path) let fetch ~origin ~query ~decoder = @@ -1993,15 +1993,14 @@ let init_public_network cloud (configuration : configuration) in let client = Client.create ~endpoint:(Node node) () in let node_rpc_endpoint = - Endpoint. - { - scheme = "http"; - host = - (match Agent.point agent with - | None -> "127.0.0.1" - | Some point -> fst point); - port = Node.rpc_port node; - } + Endpoint.make + ~scheme:"http" + ~host: + (match Agent.point agent with + | None -> "127.0.0.1" + | Some point -> fst point) + ~port:(Node.rpc_port node) + () in let bootstrap = { @@ -2279,15 +2278,14 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) in let node_rpc_endpoint = - Endpoint. - { - scheme = "http"; - host = - (match Agent.point agent with - | None -> "127.0.0.1" - | Some point -> fst point); - port = Node.rpc_port bootstrap_node; - } + Endpoint.make + ~scheme:"http" + ~host: + (match Agent.point agent with + | None -> "127.0.0.1" + | Some point -> fst point) + ~port:(Node.rpc_port bootstrap_node) + () in let (bootstrap : bootstrap) = { diff --git a/tezt/tests/cloud/network.ml b/tezt/tests/cloud/network.ml index c95b19f2ea10cc0c6299fa30b327a0ff6975cc4c..13ad543ca1d9fa01346666115b9f8a6ba4b0ca38 100644 --- a/tezt/tests/cloud/network.ml +++ b/tezt/tests/cloud/network.ml @@ -27,18 +27,17 @@ let default_protocol : t -> Protocol.t = function | `Rionet -> R022 let public_rpc_endpoint testnet = - Endpoint. - { - scheme = "https"; - host = - (match testnet with - | `Mainnet -> "rpc.tzbeta.net" - | `Ghostnet -> "rpc.ghostnet.teztnets.com" - | `Nextnet date -> sf "rpc.nextnet-%s.teztnets.com" date - | `Weeklynet date -> sf "rpc.weeklynet-%s.teztnets.com" date - | `Rionet -> "rpc.rionet.teztnets.com"); - port = 443; - } + Endpoint.make + ~scheme:"https" + ~host: + (match testnet with + | `Mainnet -> "rpc.tzbeta.net" + | `Ghostnet -> "rpc.ghostnet.teztnets.com" + | `Nextnet date -> sf "rpc.nextnet-%s.teztnets.com" date + | `Weeklynet date -> sf "rpc.weeklynet-%s.teztnets.com" date + | `Rionet -> "rpc.rionet.teztnets.com") + ~port:443 + () let snapshot_service = function | `Mainnet -> "https://snapshots.eu.tzinit.org/mainnet" @@ -99,12 +98,11 @@ let versions network = decoder) in let endpoint = - Endpoint. - { - host = Format.asprintf "api.%s.tzkt.io" (to_string public_network); - scheme = "https"; - port = 443; - } + Endpoint.make + ~host:(Format.asprintf "api.%s.tzkt.io" (to_string public_network)) + ~scheme:"https" + ~port:443 + () in let* response = RPC_core.call_raw endpoint rpc in try @@ -144,12 +142,11 @@ let delegates ?(accounts = []) network = decoder) in let endpoint = - Endpoint. - { - host = Format.asprintf "api.%s.tzkt.io" (to_string network); - scheme = "https"; - port = 443; - } + Endpoint.make + ~host:(Format.asprintf "api.%s.tzkt.io" (to_string network)) + ~scheme:"https" + ~port:443 + () in let* response = RPC_core.call_raw endpoint rpc in try diff --git a/tezt/tests/rpc_process.ml b/tezt/tests/rpc_process.ml index 07b8bc11426904a5dba494b15008e6c956b42bb5..c5f7ac9b590d09c72c27492ff313bc68d1a7b6d3 100644 --- a/tezt/tests/rpc_process.ml +++ b/tezt/tests/rpc_process.ml @@ -232,7 +232,7 @@ let wait_for_starting_rpc_server_event ~local ?fail node port = let make_endpoint port = Client.Foreign_endpoint - Endpoint.{host = Constant.default_host; scheme = "http"; port} + (Endpoint.make ~host:Constant.default_host ~scheme:"http" ~port ()) let test_local_rpc_server = Test.register