Skip to content

Commit 306cca3

Browse files
adds 200k block load by hash test
fixup: removed extra teardown
1 parent 7d38d13 commit 306cca3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

deku-p/src/core/block_storage/tests/block_storage_tests.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ let block ~default_block_size =
2828

2929
(* NOTE: These tests generate new databases in /tmp/ for every test, for every run. *)
3030
let uri () =
31-
let file_hash =
32-
let randn = Stdlib.Random.int 230 in
33-
Deku_crypto.BLAKE2b.hash (Int.to_string randn) |> BLAKE2b.to_hex
31+
let file_hash =
32+
let randn = Stdlib.Random.int 230 in
33+
Deku_crypto.BLAKE2b.hash (Int.to_string randn) |> BLAKE2b.to_hex
3434
in
3535
Uri.of_string (Format.sprintf "sqlite3:/tmp/%s.db" file_hash)
3636

@@ -106,7 +106,7 @@ let test_empty_block_and_votes env () =
106106
let test_200k_block_load env () =
107107
Eio.Switch.run @@ fun sw ->
108108
let block_storage = make_block_storage env sw in
109-
let (Block { hash; _ } as block) = block ~default_block_size:200_000 in
109+
let (Block { hash; level; _ } as block) = block ~default_block_size:200_000 in
110110
Block_storage.save_block ~block block_storage;
111111
let retrieved_block =
112112
match Block_storage.find_block_by_hash ~block_hash:hash block_storage with
@@ -117,6 +117,16 @@ let test_200k_block_load env () =
117117
~msg:"hash loaded block is equal to saved block" ~expected:block
118118
~actual:retrieved_block;
119119

120+
let retrieved_block =
121+
match Block_storage.find_block_by_level ~level block_storage with
122+
| Some json -> Block.t_of_yojson json
123+
| None -> Genesis.block
124+
in
125+
126+
Alcotest.(check' block_testable)
127+
~msg:"level loaded block is equal to saved block" ~expected:block
128+
~actual:retrieved_block;
129+
120130
(* TODO: Fail the switch and capture the exception instead *)
121131
let (Block_storage.Storage { worker; _ }) = block_storage in
122132
Parallel.Worker.teardown worker

0 commit comments

Comments
 (0)