diff --git a/src/lib_test_helpers/node_helpers.ml b/src/lib_test_helpers/node_helpers.ml index 2008e63f4..8eec6a42a 100644 --- a/src/lib_test_helpers/node_helpers.ml +++ b/src/lib_test_helpers/node_helpers.ml @@ -26,7 +26,7 @@ let handle_error res log_file_name = ignore (Sys.command (Printf.sprintf "cat %s" log_file_name) : int) ; raise Node_exited_prematurely -let fork_node ?(timeout = 4) ?(port = 18732) ?sandbox () = +let fork_node ?exe ?(timeout = 4) ?(port = 18732) ?sandbox () = let data_dir = Printf.sprintf "%s/tezos_node_%6X" @@ -37,14 +37,17 @@ let fork_node ?(timeout = 4) ?(port = 18732) ?sandbox () = let log_fd = Unix.descr_of_out_channel log_file in let null_fd = Unix.(openfile "/dev/null" [O_RDONLY] 0o644) in let exe = - let (//) = Filename.concat in - try - let path = Sys.argv.(1) in - if Filename.is_relative path then - Sys.getcwd () // ".." // path - else - path - with _ -> Sys.getcwd () // ".." // "bin_node" // "main.exe" in + match exe with + | Some exe -> exe + | None -> + let (//) = Filename.concat in + try + let path = Sys.argv.(1) in + if Filename.is_relative path then + Sys.getcwd () // ".." // path + else + path + with _ -> Sys.getcwd () // ".." // "bin_node" // "main.exe" in Format.eprintf "EXE %s@." exe ; let pid = Unix.create_process exe diff --git a/src/lib_test_helpers/node_helpers.mli b/src/lib_test_helpers/node_helpers.mli index 7cdb32ce1..365eaad0d 100644 --- a/src/lib_test_helpers/node_helpers.mli +++ b/src/lib_test_helpers/node_helpers.mli @@ -8,7 +8,8 @@ (**************************************************************************) val fork_node: - ?timeout:int -> ?port:int -> ?sandbox:string -> unit -> int + ?exe:string -> ?timeout:int -> ?port:int -> ?sandbox:string -> + unit -> int (** [fork_node ()] forks a node in sandbox mode listening to rpc on `localhost:port` (where the default port is 18732) and returns the PID of the forked process. It waits `timeout` seconds (default 4) diff --git a/test/proto_alpha/jbuild b/src/proto_alpha/lib_client/test/jbuild similarity index 91% rename from test/proto_alpha/jbuild rename to src/proto_alpha/lib_client/test/jbuild index a6de8ba0f..161508393 100644 --- a/test/proto_alpha/jbuild +++ b/src/proto_alpha/lib_client/test/jbuild @@ -31,9 +31,8 @@ (alias ((name runtest_endorsement) - (deps (sandbox.json)) (locks (/tcp-port/18100)) - (action (chdir ${ROOT} (run ${exe:test_endorsement.exe} ${bin:tezos-node}))))) + (action (chdir ${ROOT} (run ${exe:test_endorsement.exe} ${bin:tezos-node} ${path:sandbox.json} 18100))))) (alias ((name runtest_michelson_parser) @@ -41,21 +40,18 @@ (alias ((name runtest_origination) - (deps (sandbox.json)) (locks (/tcp-port/18200)) - (action (chdir ${ROOT} (run ${exe:test_origination.exe} ${bin:tezos-node}))))) + (action (chdir ${ROOT} (run ${exe:test_origination.exe} ${bin:tezos-node} ${path:sandbox.json} 18200))))) (alias ((name runtest_transaction) - (deps (sandbox.json)) (locks (/tcp-port/18300)) - (action (chdir ${ROOT} (run ${exe:test_transaction.exe} ${bin:tezos-node}))))) + (action (chdir ${ROOT} (run ${exe:test_transaction.exe} ${bin:tezos-node} ${path:sandbox.json} 18300))))) (alias ((name runtest_vote) - (deps (sandbox-vote.json)) (locks (/tcp-port/18400)) - (action (chdir ${ROOT} (run ${exe:test_vote.exe} ${bin:tezos-node}))))) + (action (chdir ${ROOT} (run ${exe:test_vote.exe} ${bin:tezos-node} ${path:sandbox-vote.json} 18400))))) (alias ((name runtest) diff --git a/test/proto_alpha/proto_alpha_helpers.ml b/src/proto_alpha/lib_client/test/proto_alpha_helpers.ml similarity index 97% rename from test/proto_alpha/proto_alpha_helpers.ml rename to src/proto_alpha/lib_client/test/proto_alpha_helpers.ml index 2a625c1b0..b9fd44635 100644 --- a/test/proto_alpha/proto_alpha_helpers.ml +++ b/src/proto_alpha/lib_client/test/proto_alpha_helpers.ml @@ -45,23 +45,17 @@ let activate_alpha () = fitness }) dictator_sk -let init ?(sandbox = "sandbox.json") ?rpc_port () = +let init ?exe ?(sandbox = "sandbox.json") ?rpc_port () = begin match rpc_port with | None -> () | Some port -> rpc_config := { !rpc_config with port } end ; - (* Handles relative path on OSX *) - let executable_path = - if Filename.is_relative Sys.argv.(0) - then Filename.concat (Sys.getcwd ()) Sys.argv.(0) - else Sys.argv.(0) in - Unix.chdir (Filename.dirname executable_path) ; - Unix.chdir ".." ; let pid = Node_helpers.fork_node + ?exe ~port:!rpc_config.port - ~sandbox:(Filename.dirname executable_path // sandbox) + ~sandbox () in activate_alpha () >>=? fun hash -> return (pid, hash) diff --git a/test/proto_alpha/proto_alpha_helpers.mli b/src/proto_alpha/lib_client/test/proto_alpha_helpers.mli similarity index 99% rename from test/proto_alpha/proto_alpha_helpers.mli rename to src/proto_alpha/lib_client/test/proto_alpha_helpers.mli index 26045eebf..c4e65a72d 100644 --- a/test/proto_alpha/proto_alpha_helpers.mli +++ b/src/proto_alpha/lib_client/test/proto_alpha_helpers.mli @@ -11,6 +11,7 @@ open Proto_alpha open Tezos_context val init : + ?exe:string -> ?sandbox:string -> ?rpc_port:int -> unit -> (int * Block_hash.t) tzresult Lwt.t diff --git a/test/proto_alpha/sandbox-vote.json b/src/proto_alpha/lib_client/test/sandbox-vote.json similarity index 100% rename from test/proto_alpha/sandbox-vote.json rename to src/proto_alpha/lib_client/test/sandbox-vote.json diff --git a/test/proto_alpha/sandbox.json b/src/proto_alpha/lib_client/test/sandbox.json similarity index 100% rename from test/proto_alpha/sandbox.json rename to src/proto_alpha/lib_client/test/sandbox.json diff --git a/test/proto_alpha/test_endorsement.ml b/src/proto_alpha/lib_client/test/test_endorsement.ml similarity index 97% rename from test/proto_alpha/test_endorsement.ml rename to src/proto_alpha/lib_client/test/test_endorsement.ml index f2409d6fb..b9ce3c030 100644 --- a/test/proto_alpha/test_endorsement.ml +++ b/src/proto_alpha/lib_client/test/test_endorsement.ml @@ -240,8 +240,12 @@ let run genesis = return () +let exe = try Sys.argv.(1) with _ -> "tezos-node" +let sandbox = try Sys.argv.(2) with _ -> "sandbox.json" +let rpc_port = try int_of_string Sys.argv.(3) with _ -> 18100 + let main () = - Helpers.init ~rpc_port:18100 () >>=? fun (_node_pid, genesis) -> + Helpers.init ~exe ~sandbox ~rpc_port () >>=? fun (_node_pid, genesis) -> run (`Hash genesis) diff --git a/test/proto_alpha/test_endorsement.mli b/src/proto_alpha/lib_client/test/test_endorsement.mli similarity index 100% rename from test/proto_alpha/test_endorsement.mli rename to src/proto_alpha/lib_client/test/test_endorsement.mli diff --git a/test/proto_alpha/test_michelson_parser.ml b/src/proto_alpha/lib_client/test/test_michelson_parser.ml similarity index 100% rename from test/proto_alpha/test_michelson_parser.ml rename to src/proto_alpha/lib_client/test/test_michelson_parser.ml diff --git a/test/proto_alpha/test_origination.ml b/src/proto_alpha/lib_client/test/test_origination.ml similarity index 90% rename from test/proto_alpha/test_origination.ml rename to src/proto_alpha/lib_client/test/test_origination.ml index d6438e626..50d2de898 100644 --- a/test/proto_alpha/test_origination.ml +++ b/src/proto_alpha/lib_client/test/test_origination.ml @@ -86,9 +86,13 @@ let run blkid ({ b1 ; b2 ; _ } : Helpers.Account.bootstrap_accounts) = return blkh +let exe = try Sys.argv.(1) with _ -> "tezos-node" +let sandbox = try Sys.argv.(2) with _ -> "sandbox.json" +let rpc_port = try int_of_string Sys.argv.(3) with _ -> 18200 + let main () = - Helpers.init ~rpc_port:18200 () >>=? fun (_node_pid, hash) -> - run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> + Helpers.init ~exe ~sandbox ~rpc_port () >>=? fun (_node_pid, genesis) -> + run (`Hash genesis) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> return () let tests = [ diff --git a/test/proto_alpha/test_origination.mli b/src/proto_alpha/lib_client/test/test_origination.mli similarity index 100% rename from test/proto_alpha/test_origination.mli rename to src/proto_alpha/lib_client/test/test_origination.mli diff --git a/test/proto_alpha/test_transaction.ml b/src/proto_alpha/lib_client/test/test_transaction.ml similarity index 92% rename from test/proto_alpha/test_transaction.ml rename to src/proto_alpha/lib_client/test/test_transaction.ml index cee3a5b77..b884f6215 100644 --- a/test/proto_alpha/test_transaction.ml +++ b/src/proto_alpha/lib_client/test/test_transaction.ml @@ -97,9 +97,13 @@ let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) = return blkh +let exe = try Sys.argv.(1) with _ -> "tezos-node" +let sandbox = try Sys.argv.(2) with _ -> "sandbox.json" +let rpc_port = try int_of_string Sys.argv.(3) with _ -> 18300 + let main () = - Helpers.init ~rpc_port:18300 () >>=? fun (_node_pid, hash) -> - run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> + Helpers.init ~exe ~sandbox ~rpc_port () >>=? fun (_node_pid, genesis) -> + run (`Hash genesis) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> return () let tests = [ diff --git a/test/proto_alpha/test_transaction.mli b/src/proto_alpha/lib_client/test/test_transaction.mli similarity index 100% rename from test/proto_alpha/test_transaction.mli rename to src/proto_alpha/lib_client/test/test_transaction.mli diff --git a/test/proto_alpha/test_vote.ml b/src/proto_alpha/lib_client/test/test_vote.ml similarity index 93% rename from test/proto_alpha/test_vote.ml rename to src/proto_alpha/lib_client/test/test_vote.ml index dab8a79f5..30fde702f 100644 --- a/test/proto_alpha/test_vote.ml +++ b/src/proto_alpha/lib_client/test/test_vote.ml @@ -85,8 +85,12 @@ let run_change_to_demo_proto block return (`Hash head) +let exe = try Sys.argv.(1) with _ -> "tezos-node" +let sandbox = try Sys.argv.(2) with _ -> "sandbox-vote.json" +let rpc_port = try int_of_string Sys.argv.(3) with _ -> 18400 + let change_to_demo_proto () = - init ~sandbox:"sandbox-vote.json" ~rpc_port:18400 () >>=? fun (_node_pid, hash) -> + init ~exe ~sandbox ~rpc_port () >>=? fun (_node_pid, hash) -> run_change_to_demo_proto (`Hash hash) Account.bootstrap_accounts >>=? fun _blkh -> return () diff --git a/test/proto_alpha/test_vote.mli b/src/proto_alpha/lib_client/test/test_vote.mli similarity index 100% rename from test/proto_alpha/test_vote.mli rename to src/proto_alpha/lib_client/test/test_vote.mli diff --git a/src/proto_alpha/lib_client/tezos-client-alpha.opam b/src/proto_alpha/lib_client/tezos-client-alpha.opam index 7bbe4715a..69dbaa00b 100644 --- a/src/proto_alpha/lib_client/tezos-client-alpha.opam +++ b/src/proto_alpha/lib_client/tezos-client-alpha.opam @@ -14,6 +14,9 @@ depends: [ "tezos-protocol-alpha" "tezos-shell-services" "tezos-client-base" + "tezos-test-helpers" { test } + "tezos-node" { test } + "tezos-client-genesis" { test } ] build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] diff --git a/src/proto_genesis/lib_client/client_proto_main.ml b/src/proto_genesis/lib_client/client_proto_main.ml index a7a145af2..caa64fba6 100644 --- a/src/proto_genesis/lib_client/client_proto_main.ml +++ b/src/proto_genesis/lib_client/client_proto_main.ml @@ -71,8 +71,7 @@ let commands () = ~name:"password" ~desc:"Dictator's key" @@ stop) begin fun timestamp hash fitness sk (cctxt : Client_commands.full_context) -> - let fitness = - Tezos_client_alpha.Proto_alpha.Fitness_repr.from_int64 fitness in + let fitness = Proto_alpha.Fitness_repr.from_int64 fitness in bake cctxt ?timestamp cctxt#block (Activate { protocol = hash ; fitness }) sk >>=? fun hash -> diff --git a/src/proto_genesis/lib_client/jbuild b/src/proto_genesis/lib_client/jbuild index cda296533..ac53a64ae 100644 --- a/src/proto_genesis/lib_client/jbuild +++ b/src/proto_genesis/lib_client/jbuild @@ -7,8 +7,8 @@ tezos-shell-services tezos-client-base tezos-protocol-environment-client - tezos-client-alpha - tezos-protocol-genesis)) + tezos-protocol-genesis + tezos-protocol-alpha)) (library_flags (:standard -linkall)) (flags (:standard -w -9+27-30-32-40@8 -safe-string diff --git a/src/proto_genesis/lib_client/proto_alpha.ml b/src/proto_genesis/lib_client/proto_alpha.ml new file mode 100644 index 000000000..68cc787c4 --- /dev/null +++ b/src/proto_genesis/lib_client/proto_alpha.ml @@ -0,0 +1,12 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +module Name = struct let name = "genesis-alpha" end +module Environment = Tezos_protocol_environment_client.Fake.Make(Name)() +include Tezos_protocol_alpha.Functor.Make(Environment) diff --git a/src/proto_genesis/lib_client/tezos-client-genesis.opam b/src/proto_genesis/lib_client/tezos-client-genesis.opam index cceaeedf0..986709c9e 100644 --- a/src/proto_genesis/lib_client/tezos-client-genesis.opam +++ b/src/proto_genesis/lib_client/tezos-client-genesis.opam @@ -13,8 +13,8 @@ depends: [ "tezos-shell-services" "tezos-client-base" "tezos-protocol-environment-client" - "tezos-client-alpha" "tezos-protocol-genesis" + "tezos-protocol-alpha" ] build: [ [ "jbuilder" "build" "-p" name "-j" jobs ]