Skip to content

Commit 8f60d75

Browse files
added level loaded empty block block_storage test
1 parent f7430a0 commit 8f60d75

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let file_hash =
2323
let randn = Stdlib.Random.int 230 in
2424
Deku_crypto.BLAKE2b.hash (Int.to_string randn) |> BLAKE2b.to_hex
2525

26+
(* TODO: change to an in-memory databse *)
2627
let uri = Uri.of_string (Format.sprintf "sqlite3:/tmp/%s.db" file_hash)
2728

2829
let make_block_storage env sw =
@@ -36,28 +37,41 @@ let test_empty_block_load env () =
3637
Parallel.Pool.run ~env ~domains:4 @@ fun () ->
3738
Eio.Switch.run @@ fun sw ->
3839
let block_storage = make_block_storage env sw in
39-
let (Block { hash; _ } as block) = block ~default_block_size:0 in
40+
let (Block { hash; level; _ } as block) = block ~default_block_size:0 in
4041
Deku_block_storage.Block_storage.save_block ~block block_storage;
4142
let retrieved_block =
4243
match
4344
Deku_block_storage.Block_storage.find_block_by_hash ~block_hash:hash
4445
block_storage
4546
with
4647
| Some json ->
47-
Format.eprintf "done!\n%!";
48-
let b =
49-
Data_encoding.Json.destruct Deku_consensus.Block.encoding json
50-
in
51-
Format.eprintf "done!\n%!";
52-
b
48+
Data_encoding.Json.destruct Deku_consensus.Block.encoding json
5349
| None -> Genesis.block
5450
in
5551
Alcotest.(check' block_testable)
5652
~msg:"hash loaded block is not equal to saved block" ~expected:block
5753
~actual:retrieved_block;
54+
let retrieved_block =
55+
match
56+
Deku_block_storage.Block_storage.find_block_by_level ~level
57+
block_storage
58+
with
59+
| Some json ->
60+
Data_encoding.Json.destruct Deku_consensus.Block.encoding json
61+
| None -> Genesis.block
62+
in
63+
64+
Alcotest.(check' block_testable)
65+
~msg:"level loaded block is equal to saved block" ~expected:block
66+
~actual:retrieved_block;
67+
5868
Eio.Switch.fail sw Test_finished
5969
with _ -> ()
6070

71+
(* TODO: Add tests with only one env threaded through all tests *)
72+
let eio_test_case : (Eio.Stdenv.t -> unit -> unit) -> unit -> unit =
73+
fun f () -> Eio_main.run (fun env -> f env ())
74+
6175
let run () =
6276
Eio_main.run (fun env ->
6377
let open Alcotest in
@@ -71,3 +85,8 @@ let run () =
7185
])
7286

7387
let () = run ()
88+
89+
(* TODO: Tests
90+
try all combinations of what's in the block_storage.mli. Use it with different block sizes, do it in parallel, try reading and writing at the same time, try reading a query that doesn't exist
91+
try reading something right before you write it and vice versa,
92+
try reading or writing two things at once *)

0 commit comments

Comments
 (0)