From 8e292297d353a7563eeeedc499b6f09088a839a4 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Fri, 9 Jun 2023 19:07:22 +0200 Subject: [PATCH] Tezt: Make the [Dac_node] module compatible with [Client.endpoint] We follow the approach used by the Client module to not assume the DAC node is communicating with an Octez node managed by Tezt. This generalizes the Dac_node module, and makes it possible to [run] a [Dac_node.t] process against a public endpoint like the one of Mondaynet for instance. --- tezt/lib_tezos/client.mli | 10 +++ tezt/lib_tezos/dac_node.ml | 152 +++++++++++++++++++++++++++--------- tezt/lib_tezos/dac_node.mli | 58 ++++++++++++++ 3 files changed, 185 insertions(+), 35 deletions(-) diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 60dea742fe26..52ab2f28b516 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -52,6 +52,16 @@ val time_of_timestamp : timestamp -> Time.t when doing RPC calls. *) val rpc_port : endpoint -> int +(** [address ?from endpoint] returns the address at which [endpoint] can be + contacted. If [from] is provided, and if [from] and [endpoint] live in the + same address, then ["127.0.0.1"] is returned (or ["localhost"] if + [hostname] is [true]. *) +val address : ?hostname:bool -> ?from:endpoint -> endpoint -> string + +(** [scheme endpoint] returns “http” or “https” depending on the configuration + of the endpoint. *) +val scheme : endpoint -> string + (** Mode of the client *) type mode = | Client of endpoint option * media_type option diff --git a/tezt/lib_tezos/dac_node.ml b/tezt/lib_tezos/dac_node.ml index f114fced9927..66532611bf6f 100644 --- a/tezt/lib_tezos/dac_node.ml +++ b/tezt/lib_tezos/dac_node.ml @@ -58,7 +58,7 @@ module Parameters = struct rpc_host : string; rpc_port : int; mode : mode_settings; - node : Node.t; + endpoint : Client.endpoint; client : Client.t; mutable pending_ready : unit option Lwt.u list; allow_v1_api : bool; @@ -100,9 +100,11 @@ let rpc_host dac_node = dac_node.persistent_state.rpc_host let rpc_port dac_node = dac_node.persistent_state.rpc_port -let layer1_addr dac_node = Node.rpc_host dac_node.persistent_state.node +let layer1_scheme dac_node = Client.scheme dac_node.persistent_state.endpoint -let layer1_port dac_node = Node.rpc_port dac_node.persistent_state.node +let layer1_addr dac_node = Client.address dac_node.persistent_state.endpoint + +let layer1_port dac_node = Client.rpc_port dac_node.persistent_state.endpoint let endpoint dac_node = Printf.sprintf "http://%s:%d" (rpc_host dac_node) (rpc_port dac_node) @@ -286,9 +288,9 @@ let wait_for_ready dac_node = let handle_event dac_node {name; value = _; timestamp = _} = match name with "dac_node_is_ready.v0" -> set_ready dac_node | _ -> () -let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe - ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~mode ~node ~client - ?(allow_v1_api = false) () = +let create_with_endpoint ?(path = Constant.dac_node) ?name ?color ?data_dir + ?event_pipe ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~mode + ~endpoint ~client ?(allow_v1_api = false) () = let name = match name with None -> fresh_name () | Some name -> name in let data_dir = match data_dir with None -> Temp.dir name | Some dir -> dir @@ -314,7 +316,7 @@ let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe rpc_port; mode; pending_ready = []; - node; + endpoint; client; allow_v1_api; } @@ -322,8 +324,25 @@ let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe on_event dac_node (handle_event dac_node) ; dac_node +let create ?path ?name ?color ?data_dir ?event_pipe ?rpc_host ?rpc_port + ?reveal_data_dir ~mode ~node ~client ?allow_v1_api () = + create_with_endpoint + ?path + ?name + ?color + ?data_dir + ?event_pipe + ?rpc_host + ?rpc_port + ?reveal_data_dir + ~mode + ~endpoint:(Client.Node node) + ~client + ?allow_v1_api + () + let create_legacy ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe - ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~threshold + ?(rpc_host = localhost) ?rpc_port ?reveal_data_dir ~threshold ~committee_members ?committee_member_address ~node ~client () = let mode = Legacy @@ -347,54 +366,92 @@ let create_legacy ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe ~client () -let create_coordinator ?(path = Constant.dac_node) ?name ?color ?data_dir - ?event_pipe ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir - ?(allow_v1_api = false) ~committee_members ~node ~client () = +let create_coordinator_with_endpoint ?path ?name ?color ?data_dir ?event_pipe + ?rpc_host ?rpc_port ?reveal_data_dir ?allow_v1_api ~committee_members + ~endpoint ~client () = let mode = Coordinator {committee_members} in - create - ~path + create_with_endpoint + ?path ?name ?color ?data_dir ?event_pipe - ~rpc_host + ?rpc_host ?rpc_port ?reveal_data_dir ~mode - ~node + ~endpoint + ~client + ?allow_v1_api + () + +let create_coordinator ?path ?name ?color ?data_dir ?event_pipe ?rpc_host + ?rpc_port ?reveal_data_dir ?allow_v1_api ~committee_members ~node ~client () + = + create_coordinator_with_endpoint + ?path + ?name + ?color + ?data_dir + ?event_pipe + ?rpc_host + ?rpc_port + ?reveal_data_dir + ?allow_v1_api + ~committee_members + ~endpoint:(Node node) ~client - ~allow_v1_api () -let create_committee_member ?(path = Constant.dac_node) ?name ?color ?data_dir - ?event_pipe ?(rpc_host = localhost) ?rpc_port ?reveal_data_dir - ?(coordinator_rpc_host = localhost) ?coordinator_rpc_port - ?(allow_v1_api = false) ~address ~node ~client () = +let create_committee_member_with_endpoint ?path ?name ?color ?data_dir + ?event_pipe ?rpc_host ?rpc_port ?reveal_data_dir + ?(coordinator_rpc_host = localhost) ?coordinator_rpc_port ?allow_v1_api + ~address ~endpoint ~client () = let coordinator_rpc_port = match coordinator_rpc_port with None -> Port.fresh () | Some port -> port in let mode = Committee_member {address; coordinator_rpc_host; coordinator_rpc_port} in - create - ~path + create_with_endpoint + ?path ?name ?color ?data_dir ?event_pipe - ~rpc_host + ?rpc_host ?rpc_port ?reveal_data_dir ~mode - ~node + ~endpoint ~client - ~allow_v1_api + ?allow_v1_api () -let create_observer ?(path = Constant.dac_node) ?name ?color ?data_dir - ?event_pipe ?(rpc_host = localhost) ?rpc_port ?reveal_data_dir - ?(coordinator_rpc_host = localhost) ?coordinator_rpc_port ?timeout - ?(allow_v1_api = false) ~committee_member_rpcs ~node ~client () = +let create_committee_member ?path ?name ?color ?data_dir ?event_pipe ?rpc_host + ?rpc_port ?reveal_data_dir ?coordinator_rpc_host ?coordinator_rpc_port + ?allow_v1_api ~address ~node ~client () = + create_committee_member_with_endpoint + ?path + ?name + ?color + ?data_dir + ?event_pipe + ?rpc_host + ?rpc_port + ?reveal_data_dir + ?coordinator_rpc_host + ?coordinator_rpc_port + ?allow_v1_api + ~address + ~endpoint:(Node node) + ~client + () + +let create_observer_with_endpoint ?path ?name ?color ?data_dir ?event_pipe + ?rpc_host ?rpc_port ?reveal_data_dir ?(coordinator_rpc_host = localhost) + ?coordinator_rpc_port ?timeout ?allow_v1_api ~committee_member_rpcs + ~endpoint ~client () = let coordinator_rpc_port = match coordinator_rpc_port with None -> Port.fresh () | Some port -> port in @@ -407,19 +464,40 @@ let create_observer ?(path = Constant.dac_node) ?name ?color ?data_dir timeout; } in - create - ~path + create_with_endpoint + ?path ?name ?color ?data_dir ?event_pipe - ~rpc_host + ?rpc_host ?rpc_port ?reveal_data_dir ~mode - ~node + ~endpoint + ~client + ?allow_v1_api + () + +let create_observer ?path ?name ?color ?data_dir ?event_pipe ?rpc_host ?rpc_port + ?reveal_data_dir ?coordinator_rpc_host ?coordinator_rpc_port ?timeout + ?allow_v1_api ~committee_member_rpcs ~node ~client () = + create_observer_with_endpoint + ?path + ?name + ?color + ?data_dir + ?event_pipe + ?rpc_host + ?rpc_port + ?reveal_data_dir + ?coordinator_rpc_host + ?coordinator_rpc_port + ?timeout + ?allow_v1_api + ~committee_member_rpcs + ~endpoint:(Node node) ~client - ~allow_v1_api () let make_arguments node = @@ -429,7 +507,11 @@ let make_arguments node = let endpoint_args = [ "--endpoint"; - Printf.sprintf "http://%s:%d" (layer1_addr node) (layer1_port node); + Printf.sprintf + "%s://%s:%d" + (layer1_scheme node) + (layer1_addr node) + (layer1_port node); ] in base_dir_args @ endpoint_args diff --git a/tezt/lib_tezos/dac_node.mli b/tezt/lib_tezos/dac_node.mli index 36cee8d47f73..cd9884715314 100644 --- a/tezt/lib_tezos/dac_node.mli +++ b/tezt/lib_tezos/dac_node.mli @@ -66,6 +66,23 @@ val create_coordinator : unit -> t +(** Same as {!create_coordinator}, but do not assume the endpoint is a node. *) +val create_coordinator_with_endpoint : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + ?allow_v1_api:bool -> + committee_members:string list -> + endpoint:Client.endpoint -> + client:Client.t -> + unit -> + t + (** Creates a DAC node to run in committee_member mode, using the specified address, coordinator rpc host and port. *) val create_committee_member : @@ -86,6 +103,26 @@ val create_committee_member : unit -> t +(** Same as {!create_committee_member}, but do not assume the endpoint is a + node. *) +val create_committee_member_with_endpoint : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + ?coordinator_rpc_host:string -> + ?coordinator_rpc_port:int -> + ?allow_v1_api:bool -> + address:string -> + endpoint:Client.endpoint -> + client:Client.t -> + unit -> + t + (** Creates a DAC node to run in observer mode, using the specified coordinator rpc host and port and set the committee member endpoints to [committee_member_rpcs]. *) @@ -108,6 +145,27 @@ val create_observer : unit -> t +(** Same as {!create_obsever}, but do not assume the endpoint is a + node. *) +val create_observer_with_endpoint : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + ?coordinator_rpc_host:string -> + ?coordinator_rpc_port:int -> + ?timeout:int -> + ?allow_v1_api:bool -> + committee_member_rpcs:(string * int) list -> + endpoint:Client.endpoint -> + client:Client.t -> + unit -> + t + (** Get the name of an dac node. *) val name : t -> string -- GitLab