Skip to content

Commit 50f2843

Browse files
committed
add test and refactor precomputed blocks test
1 parent 5c95b12 commit 50f2843

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

src/test/archive/archive_node_tests/archive_node_tests.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ let () =
2323
.Make_FixtureWithoutBootstrap
2424
(Load_genesis_ledger) ) )
2525
] )
26+
; ( "upgrade_archive"
27+
, [ test_case
28+
"Recreate database from precomputed blocks after upgrade script is \
29+
applied"
30+
`Quick
31+
(Runner.run_blocking
32+
( module Mina_automation_fixture.Archive.Make_FixtureWithBootstrap
33+
(Upgrade_archive) ) )
34+
] )
2635
]

src/test/archive/archive_node_tests/archive_precomputed_blocks_test.ml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open Async
22
open Core
33
open Mina_automation
44
open Mina_automation_fixture.Archive
5+
open Common
56

67
(**
78
* Test the basic functionality of the mina archive with mocked deamon
@@ -118,11 +119,8 @@ let test_case (test_data : t) =
118119
let archive_uri = test_data.archive.config.postgres_uri in
119120
let output = test_data.temp_dir in
120121
let%bind precomputed_blocks =
121-
Network_data.untar_precomputed_blocks test_data.network_data output
122-
in
123-
let precomputed_blocks =
124-
List.map precomputed_blocks ~f:(fun file -> output ^ "/" ^ file)
125-
|> List.filter ~f:(fun file -> String.is_suffix file ~suffix:".json")
122+
unpack_precomputed_blocks test_data.network_data
123+
~temp_dir:test_data.temp_dir
126124
in
127125
let log_file = output ^ "/precomputed_blocks_test.log" in
128126
Archive.Process.start_logging test_data.archive ~log_file ;
@@ -136,32 +134,13 @@ let test_case (test_data : t) =
136134
assert_archived_blocks ~archive_uri
137135
~expected:(List.length precomputed_blocks)
138136
in
139-
let connection = Psql.Conn_str archive_uri in
140-
let%bind latest_state_hash =
141-
Psql.run_command ~connection
142-
"SELECT state_hash FROM blocks ORDER BY id DESC LIMIT 1"
143-
in
144-
let latest_state_hash =
145-
match latest_state_hash with
146-
| Ok hash ->
147-
hash
148-
| Error err ->
149-
failwith
150-
("Failed to query latest state hash: " ^ Error.to_string_hum err)
151-
in
152-
let output_ledger = output ^ "/output_ledger.json" in
153-
let replayer = Replayer.default in
154-
let%bind replayer_output =
155-
Replayer.run replayer ~archive_uri
156-
~input_config:
137+
138+
let%bind () =
139+
assert_replayer_run_against_last_block
140+
~replayer_input_file_path:
157141
(Network_data.replayer_input_file_path test_data.network_data)
158-
~target_state_hash:latest_state_hash ~interval_checkpoint:10
159-
~output_ledger ()
142+
archive_uri test_data.temp_dir
160143
in
161-
let () = print_endline replayer_output in
162-
let output_ledger = Replayer.Output.of_json_file_exn output_ledger in
163-
assert (
164-
String.equal output_ledger.target_epoch_ledgers_state_hash latest_state_hash ) ;
165144

166145
let%bind perf_data = extract_perf_metrics log_file in
167146
perf_metrics_to_yojson perf_data |> Yojson.to_file "archive.perf" ;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
open Async
2+
open Core
3+
open Mina_automation
4+
open Mina_automation_fixture.Archive
5+
open Common
6+
7+
type t = Mina_automation_fixture.Archive.after_bootstrap
8+
9+
let test_case (test_data : t) =
10+
let open Deferred.Let_syntax in
11+
let daemon = Daemon.default in
12+
let archive_uri = test_data.archive.config.postgres_uri in
13+
let temp_dir = test_data.temp_dir in
14+
let%bind precomputed_blocks =
15+
unpack_precomputed_blocks ~temp_dir test_data.network_data
16+
in
17+
let log_file = temp_dir ^ "/upgrade.log" in
18+
let upgrade_path =
19+
Archive.Scripts.filepath `Upgrade
20+
|> Option.value_exn ~message:"Failed to find upgrade script"
21+
in
22+
let%bind _ =
23+
Psql.run_script ~connection:(Psql.Conn_str archive_uri) upgrade_path
24+
in
25+
26+
Archive.Process.start_logging test_data.archive ~log_file ;
27+
let%bind () =
28+
Daemon.archive_blocks_from_files daemon
29+
~archive_address:test_data.archive.config.server_port
30+
~format:Archive_blocks.Precomputed precomputed_blocks
31+
in
32+
33+
let%bind () =
34+
assert_replayer_run_against_last_block
35+
~replayer_input_file_path:
36+
(Network_data.replayer_input_file_path test_data.network_data)
37+
archive_uri temp_dir
38+
in
39+
40+
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed

0 commit comments

Comments
 (0)