1313
1414module Executor = Executor. Make (Paths )
1515
16- type t = Executor .t
17-
1816let logger = Logger. create ()
1917
18+ let path () =
19+ Deferred. map Executor.PathFinder. standalone_path ~f: (fun opt ->
20+ Option. value_exn opt
21+ ~message:
22+ " Could not find released mina daemon environment. App is not \
23+ executable outside the dune" )
24+
2025(* *
2126 Module [Client] provides functions to interact with a Mina daemon.
2227*)
2328module Client = struct
2429 type t = { port : int ; executor : Executor .t }
2530
26- let create ?(port = 3085 ) ?(executor = Executor. AutoDetect ) () =
31+ let create ?(port = 8031 ) ?(executor = Executor. AutoDetect ) () =
2732 { port; executor }
2833
2934 (* * [stop_daemon t] stops the daemon running on the specified port.
3035 @param t The daemon instance containing the executor and port information.
3136 @return Unit. Executes the command to stop the daemon using the executor.
3237 *)
33- let stop_daemon t =
34- Executor. run t.executor
35- ~args: [ " client" ; " stop-daemon" ; " -daemon-port" ; sprintf " %d" t.port ]
36- ()
38+ let stop_daemon t : unit Deferred.t =
39+ let % map _ =
40+ Executor. run t.executor
41+ ~args: [ " client" ; " stop-daemon" ; " -daemon-port" ; sprintf " %d" t.port ]
42+ ()
43+ in
44+ ()
3745
3846 (* * [daemon_status t] retrieves the status of the daemon running on the specified port.
3947 It executes the command `client status -daemon-port <port>` using the provided executor.
@@ -53,8 +61,8 @@ module Client = struct
5361 @param retry_attempts The number of retries.
5462 @return A deferred result indicating the success or failure of the operation.
5563 *)
56- let wait_for_bootstrap t ?(client_delay = 40 . ) ?(retry_delay = 60. )
57- ?(retry_attempts = 10 ) () =
64+ let wait_for_bootstrap t ?(client_delay = 60 . ) ?(retry_delay = 60. )
65+ ?(retry_attempts = 40 ) () =
5866 Async. printf " Waiting initial %d s. before connecting\n "
5967 (int_of_float client_delay) ;
6068 let % bind _ =
@@ -74,6 +82,33 @@ module Client = struct
7482 else Deferred.Or_error. error_string output
7583 in
7684 go retry_attempts
85+
86+ let ledger_hash t ~ledger_file =
87+ Executor. run t.executor
88+ ~args: [ " ledger" ; " hash" ; " --ledger-file" ; ledger_file ]
89+ ()
90+
91+ let ledger_currency t ~ledger_file =
92+ Executor. run t.executor
93+ ~args: [ " ledger" ; " currency" ; " --ledger-file" ; ledger_file ]
94+ ()
95+
96+ let test_ledger t ~(n : int ) =
97+ Executor. run t.executor
98+ ~args: [ " ledger" ; " test" ; " generate-accounts" ; " -n" ; string_of_int n ]
99+ ()
100+
101+ let advanced_print_signature_kind t =
102+ Executor. run t.executor ~args: [ " advanced" ; " print-signature-kind" ] ()
103+
104+ let advanced_compile_time_constants t ~config_file =
105+ Executor. run t.executor
106+ ~env: (`Extend [ (" MINA_CONFIG_FILE" , config_file) ])
107+ ~args: [ " advanced" ; " compile-time-constants" ]
108+ ()
109+
110+ let advanced_constraint_system_digests t =
111+ Executor. run t.executor ~args: [ " advanced" ; " constraint-system-digests" ] ()
77112end
78113
79114module Config = struct
@@ -90,6 +125,8 @@ module Config = struct
90125 let create ?(root_path = " /tmp" ) ?(config_dir = " mina_spun_test" )
91126 ?(genesis_dir = " mina_genesis_state" )
92127 ?(p2p_dir = " mina_test_libp2p_keypair" ) () =
128+ Unix. putenv ~key: " MINA_LIBP2P_PASS" ~data: " naughty blue worm" ;
129+ Unix. putenv ~key: " MINA_PRIVKEY_PASS" ~data: " naughty blue worm" ;
93130 (* create empty config dir to avoid any issues with the default config dir *)
94131 let conf = Filename. temp_dir ~in_dir: root_path config_dir " " in
95132 let genesis = Filename. temp_dir ~in_dir: root_path genesis_dir " " in
@@ -103,9 +140,9 @@ module Config = struct
103140
104141 type t = { port : int ; dirs : ConfigDirs .t }
105142
106- let default ?dirs =
143+ let default ?dirs () =
107144 let root_path = Filename. temp_dir ~in_dir: " /tmp" " mina_automation" " " in
108- { port = 3085
145+ { port = 8031
109146 ; dirs =
110147 ( match dirs with
111148 | Some dirs ->
@@ -117,11 +154,7 @@ module Config = struct
117154 let libp2p_keypair_folder t = ConfigDirs. libp2p_keypair_folder t.dirs
118155
119156 let generate_keys t =
120- let open Deferred.Let_syntax in
121- let % map () =
122- Init.Client. generate_libp2p_keypair_do (libp2p_keypair_folder t) ()
123- in
124- ()
157+ Init.Client. generate_libp2p_keypair_do (libp2p_keypair_folder t) ()
125158end
126159
127160(* *
@@ -137,53 +170,67 @@ module Process = struct
137170 let force_kill t = Utils. force_kill t.process
138171end
139172
140- let archive_blocks t ~archive_address ~(format : Archive_blocks.format ) blocks =
173+ let archive_blocks t ~archive_address ~format blocks =
174+ let format_arg =
175+ match format with
176+ | `Precomputed ->
177+ " --precomputed"
178+ | `Extensional ->
179+ " --extensional"
180+ in
141181 Executor. run t
142182 ~args:
143183 ( [ " advanced"
144184 ; " archive-blocks"
145185 ; " --archive-addres"
146186 ; string_of_int archive_address
147- ; " - " ^ Archive_blocks. format_to_string format
187+ ; format_arg
148188 ]
149189 @ blocks )
150190
151- let archive_blocks_from_files t ~archive_address
152- ~(format : Archive_blocks.format ) ?(sleep = 5 ) blocks =
191+ let archive_blocks_from_files t ~archive_address ~format ?(sleep = 5 ) blocks =
153192 Deferred.List. iter blocks ~f: (fun block ->
154193 let % bind _ = archive_blocks t ~archive_address ~format [ block ] () in
155194 after (Time.Span. of_sec (Float. of_int sleep)) )
156195
157- let default = Executor. default
196+ type t = { config : Config .t ; executor : Executor .t }
158197
159- let client t ~( config : Config.t ) = Client. create ~port: config.port t
198+ let of_config config = { config; executor = Executor. AutoDetect }
160199
161- let start t (config : Config.t ) =
200+ let default () = { config = Config. default () ; executor = Executor. AutoDetect }
201+
202+ let client t = Client. create ~port: t.config.port ~executor: t.executor ()
203+
204+ let start t =
205+ let open Deferred.Let_syntax in
162206 let args =
163207 [ " daemon"
164208 ; " --seed"
165209 ; " --demo-mode"
166- ; " -background"
210+ ; " -- background"
167211 ; " --working-dir"
168212 ; " ."
169213 ; " --client-port"
170- ; sprintf " %d " config.port
214+ ; string_of_int t. config.port
171215 ; " --config-directory"
172- ; config.dirs.conf
216+ ; t. config.dirs.conf
173217 ; " --genesis-ledger-dir"
174- ; config.dirs.genesis
218+ ; t. config.dirs.genesis
175219 ; " --external-ip"
176220 ; " 0.0.0.0"
177221 ; " --libp2p-keypair"
178- ; Config. libp2p_keypair_folder config
222+ ; Config. libp2p_keypair_folder t. config
179223 ]
180224 in
181225
182226 [% log debug] " Starting daemon" ;
183227
184- let % bind _, process = Executor. run_in_background t ~args () in
228+ let % bind _, process = Executor. run_in_background t.executor ~args () in
185229
186230 let mina_process : Process.t =
187- { config; process; client = Client. create ~port: config.port ~executor: t () }
231+ { config = t.config
232+ ; process
233+ ; client = Client. create ~port: t.config.port ~executor: t.executor ()
234+ }
188235 in
189236 Deferred. return mina_process
0 commit comments