File tree Expand file tree Collapse file tree 7 files changed +88
-12
lines changed
archive/archive_node_tests Expand file tree Collapse file tree 7 files changed +88
-12
lines changed Original file line number Diff line number Diff line change 1+ open Async
2+ open Core
3+ open Mina_automation
4+
5+ let assert_replayer_run_against_last_block ~replayer_input_file_path archive_uri
6+ output =
7+ let open Deferred.Let_syntax in
8+ let connection = Psql. Conn_str archive_uri in
9+ let % bind latest_state_hash =
10+ Psql. run_command ~connection
11+ " SELECT state_hash FROM blocks ORDER BY id DESC LIMIT 1"
12+ in
13+ let latest_state_hash =
14+ match latest_state_hash with
15+ | Ok hash ->
16+ hash
17+ | Error err ->
18+ failwith
19+ (" Failed to query latest state hash: " ^ Error. to_string_hum err)
20+ in
21+ let output_ledger = output ^ " /output_ledger.json" in
22+ let replayer = Replayer. default in
23+ let % bind replayer_output =
24+ Replayer. run replayer ~archive_uri ~input_config: replayer_input_file_path
25+ ~target_state_hash: latest_state_hash ~interval_checkpoint: 10
26+ ~output_ledger ()
27+ in
28+ let () = print_endline replayer_output in
29+ let output_ledger = Replayer.Output. of_json_file_exn output_ledger in
30+ assert (
31+ String. equal output_ledger.target_epoch_ledgers_state_hash latest_state_hash ) ;
32+ Deferred. unit
33+
34+ let unpack_precomputed_blocks ~temp_dir source =
35+ let open Deferred.Let_syntax in
36+ let % bind precomputed_blocks =
37+ Network_data. untar_precomputed_blocks source temp_dir
38+ in
39+ List. map precomputed_blocks ~f: (fun file -> temp_dir ^ " /" ^ file)
40+ |> List. filter ~f: (fun file -> String. is_suffix file ~suffix: " .json" )
41+ |> Deferred. return
Original file line number Diff line number Diff line change @@ -35,6 +35,28 @@ module Paths = struct
3535 let official_name = " mina-archive"
3636end
3737
38+ module Scripts = struct
39+ type t = [ `CreateSchema | `DropTables | `Upgrade | `Rollback ]
40+
41+ let possible_locations = [ " /etc/mina/archive" ; " src/app/archive" ]
42+
43+ let file t =
44+ match t with
45+ | `CreateSchema ->
46+ " create_schema.sql"
47+ | `DropTables ->
48+ " drop_tables.sql"
49+ | `Upgrade ->
50+ " upgrade-to-mesa.sql"
51+ | `Rollback ->
52+ " rollback_to-berkeley.sql"
53+
54+ let filepath t =
55+ let file = file t in
56+ let possible_locations = [ " /etc/mina/archive" ; " src/app/archive" ] in
57+ Utils. possible_locations ~file possible_locations
58+ end
59+
3860module Executor = Executor. Make (Paths )
3961
4062type t = { config : Config .t ; executor : Executor .t }
Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ let path () =
2323 Deferred. map Executor.PathFinder. standalone_path ~f: (fun opt ->
2424 Option. value_exn opt
2525 ~message:
26- " Could not find standalone path for archive blocks. App is not \
27- executable outside the dune" )
26+ " Could not find standalone path for archive blocks. Archive blocks \
27+ is not executable outside the dune" )
2828
2929let format_to_string format =
3030 match format with
Original file line number Diff line number Diff line change @@ -33,9 +33,6 @@ let logger = Logger.create ()
3333module Make_PathFinder (P : AppPaths ) = struct
3434 module Paths = P
3535
36- let paths =
37- Option. value_map ~f: (String. split ~on: ':' ) ~default: [] (Sys. getenv " PATH" )
38-
3936 let built_name = Printf. sprintf " _build/default/%s" P. dune_name
4037
4138 let exists_at_path path prefix =
@@ -51,7 +48,7 @@ module Make_PathFinder (P : AppPaths) = struct
5148 Deferred. return (Some built_name)
5249 | _ -> (
5350 match % bind
54- Deferred.List. find_map ~f: (exists_at_path P. official_name) paths
51+ Deferred.List. find_map ~f: (exists_at_path P. official_name) Utils. paths
5552 with
5653 | Some _ ->
5754 Deferred. return (Some P. official_name)
@@ -133,7 +130,7 @@ module Make (P : AppPaths) = struct
133130 match % bind
134131 Deferred.List. find_map
135132 ~f: (PathFinder. exists_at_path PathFinder.Paths. official_name)
136- PathFinder . paths
133+ Utils . paths
137134 with
138135 | Some prefix ->
139136 f_debian ~args ~prefix ?env ()
Original file line number Diff line number Diff line change @@ -17,5 +17,5 @@ let path () =
1717 Deferred. map PathFinder. standalone_path ~f: (fun opt ->
1818 Option. value_exn opt
1919 ~message:
20- " Could not find standalone path for missing block auditor. App is \
21- not executable outside the dune" )
20+ " Could not find standalone for missing block auditor. Missing block \
21+ auditor is not executable outside the dune" )
Original file line number Diff line number Diff line change @@ -82,9 +82,10 @@ let run_command ~connection command =
8282 @return A deferred string containing the output of the command.
8383*)
8484
85- let run_script ~connection ~db script =
85+ let run_script ~connection ?db script =
86+ let maybe_db = Option. value_map db ~default: [] ~f: (fun db -> [ " -d" ; db ]) in
8687 let creds = create_credential_arg ~connection in
87- Util. run_cmd_exn " ." psql (creds @ [ " -d " ; db; " -a" ; " -f" ; script ])
88+ Util. run_cmd_exn " ." psql (creds @ maybe_db @ [ " -a" ; " -f" ; script ])
8889
8990let create_empty_db ~connection ~db =
9091 run_command ~connection (sprintf " CREATE DATABASE %s;" db)
Original file line number Diff line number Diff line change 11open Integration_test_lib
22open Async
3- open Core_kernel
3+ open Core
4+
5+ let paths =
6+ Option. value_map ~f: (String. split ~on: ':' ) ~default: [] (Sys. getenv " PATH" )
7+
8+ let possible_locations ~file possible_locations =
9+ let exists_at_path folder file =
10+ match Sys. file_exists (folder ^ " /" ^ file) with
11+ | `Yes ->
12+ Some (folder ^ " /" ^ file)
13+ | _ ->
14+ None
15+ in
16+
17+ possible_locations @ paths
18+ |> List. find_map ~f: (fun folder -> exists_at_path folder file)
419
520let wget ~url ~target = Util. run_cmd_exn " ." " wget" [ " -c" ; url; " -O" ; target ]
621
You can’t perform that action at this time.
0 commit comments