Skip to content

Commit 77430d9

Browse files
committed
fix various review change requests
1 parent ce24e6d commit 77430d9

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/test/archive/archive_node_tests/archive_node_tests.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ open Mina_automation_fixture.Archive
1212
let assert_archived_blocks ~archive_uri ~expected =
1313
let connection = Psql.Conn_str archive_uri in
1414
let%bind actual_blocks_count =
15-
Psql.run_command ~connection "Select count(*) from blocks where height > 0"
15+
Psql.run_command ~connection "SELECT COUNT(*) FROM blocks WHERE height > 1"
1616
in
1717
let actual_blocks_count =
18-
actual_blocks_count |> String.strip |> Int.of_string
18+
match actual_blocks_count with
19+
| Ok count ->
20+
Int.of_string count
21+
| Error err ->
22+
failwith ("Failed to query blocks count: " ^ Error.to_string_hum err)
1923
in
2024
if Int.( <> ) actual_blocks_count expected then
2125
failwithf "Invalid number of archive blocks. Actual (%d) vs Expected (%d)"
@@ -38,7 +42,7 @@ module ArchivePrecomputedBlocksFromDaemon = struct
3842
in
3943
Archive.Process.start_logging test_data.archive ;
4044
let%bind () =
41-
Daemon.dispatch_blocks daemon
45+
Daemon.archive_blocks_from_files daemon
4246
~archive_address:test_data.archive.config.server_port
4347
~format:Archive_blocks.Precomputed precomputed_blocks
4448
in
@@ -49,19 +53,19 @@ module ArchivePrecomputedBlocksFromDaemon = struct
4953
in
5054
let connection = Psql.Conn_str archive_uri in
5155
let%bind latest_state_hash =
52-
Psql.run_command ~connection
53-
"select state_hash from blocks WHERE id=(SELECT max(id) FROM blocks) \
54-
LIMIT 1"
56+
Psql.run_command_exn ~connection
57+
"SELECT state_hash FROM blocks ORDER BY id DESC LIMIT 1"
5558
in
5659
let output_ledger = output ^ "/output_ledger.json" in
5760
let replayer = Replayer.default in
58-
let%bind _ =
61+
let%bind output =
5962
Replayer.run replayer ~archive_uri
6063
~input_config:
6164
(Network_data.replayer_input_file_path test_data.network_data)
6265
~target_state_hash:latest_state_hash ~interval_checkpoint:10
6366
~output_ledger ()
6467
in
68+
let () = print_endline output in
6569
let output_ledger = Replayer.Output.of_json_file_exn output_ledger in
6670
assert (
6771
String.equal output_ledger.target_epoch_ledgers_state_hash

src/test/mina_automation/daemon.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ let archive_blocks t ~archive_address ~(format : Archive_blocks.format) blocks =
148148
]
149149
@ blocks )
150150

151-
let dispatch_blocks t ~archive_address ~(format : Archive_blocks.format)
152-
?(sleep = 5) blocks =
151+
let archive_blocks_from_files t ~archive_address
152+
~(format : Archive_blocks.format) ?(sleep = 5) blocks =
153153
Deferred.List.iter blocks ~f:(fun block ->
154154
Core.Unix.sleep sleep ;
155155
archive_blocks t ~archive_address ~format [ block ] () >>| ignore )

src/test/mina_automation/psql.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,23 @@ let create_credential_arg ~connection =
6868
@ value_or_empty "-U" credentials.user
6969
@ value_or_empty "-d" credentials.db
7070

71-
(** [run_command ~connection command] runs a SQL command using psql with the given connection.
71+
(** [run_command_exn ~connection command] runs a SQL command using psql with the given connection.
7272
The command is executed in the current directory, and the output is stripped of leading and trailing whitespace.
73+
It raises an exception if the command fails.
7374
7475
@param connection The connection string or credentials to connect to the PostgreSQL database.
7576
@param command The SQL command to execute.
7677
@return A deferred string containing the output of the command.
7778
*)
78-
let run_command ~connection command =
79+
let run_command_exn ~connection command =
7980
let creds = create_credential_arg ~connection in
8081
Util.run_cmd_exn "." psql (creds @ [ "-c"; command; "-t" ]) >>| String.strip
8182

83+
let run_command ~connection command =
84+
let creds = create_credential_arg ~connection in
85+
Util.run_cmd_or_error "." psql (creds @ [ "-c"; command ])
86+
>>| Result.map ~f:String.strip
87+
8288
let run_script ~connection ~db script =
8389
let creds = create_credential_arg ~connection in
8490
Util.run_cmd_exn "." psql (creds @ [ "-d"; db; "-a"; "-f"; script ])

0 commit comments

Comments
 (0)