Skip to content

Commit 89158c4

Browse files
added level loaded empty block block_storage test
1 parent e5268a5 commit 89158c4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
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 =
@@ -35,7 +36,7 @@ let test_empty_block_load env () =
3536
try
3637
Eio.Switch.run @@ fun sw ->
3738
let block_storage = make_block_storage env sw in
38-
let (Block { hash; _ } as block) = block ~default_block_size:0 in
39+
let (Block { hash; level; _ } as block) = block ~default_block_size:0 in
3940
Deku_block_storage.Block_storage.save_block ~block block_storage;
4041
let retrieved_block =
4142
match
@@ -48,6 +49,19 @@ let test_empty_block_load env () =
4849
Alcotest.(check' block_testable)
4950
~msg:"hash loaded block is not equal to saved block" ~expected:block
5051
~actual:retrieved_block;
52+
let retrieved_block =
53+
match
54+
Deku_block_storage.Block_storage.find_block_by_level ~level
55+
block_storage
56+
with
57+
| Some block -> block
58+
| None -> Genesis.block
59+
in
60+
61+
Alcotest.(check' block_testable)
62+
~msg:"level loaded block is equal to saved block" ~expected:block
63+
~actual:retrieved_block;
64+
5165
Eio.Switch.fail sw Test_finished
5266
with _ -> ()
5367

@@ -64,3 +78,8 @@ let run () =
6478
])
6579

6680
let () = run ()
81+
82+
(* TODO: Tests
83+
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
84+
try reading something right before you write it and vice versa,
85+
try reading or writing two things at once *)

0 commit comments

Comments
 (0)