diff --git a/deku-p/src/core/block_storage/tests/block_storage_tests.ml b/deku-p/src/core/block_storage/tests/block_storage_tests.ml index 467609973..374faf020 100644 --- a/deku-p/src/core/block_storage/tests/block_storage_tests.ml +++ b/deku-p/src/core/block_storage/tests/block_storage_tests.ml @@ -23,6 +23,7 @@ let file_hash = let randn = Stdlib.Random.int 230 in Deku_crypto.BLAKE2b.hash (Int.to_string randn) |> BLAKE2b.to_hex +(* TODO: change to an in-memory databse *) let uri = Uri.of_string (Format.sprintf "sqlite3:/tmp/%s.db" file_hash) let make_block_storage env sw = @@ -36,7 +37,7 @@ let test_empty_block_load env () = Parallel.Pool.run ~env ~domains:4 @@ fun () -> Eio.Switch.run @@ fun sw -> let block_storage = make_block_storage env sw in - let (Block { hash; _ } as block) = block ~default_block_size:0 in + let (Block { hash; level; _ } as block) = block ~default_block_size:0 in Deku_block_storage.Block_storage.save_block ~block block_storage; let retrieved_block = match @@ -44,20 +45,33 @@ let test_empty_block_load env () = block_storage with | Some json -> - Format.eprintf "done!\n%!"; - let b = - Data_encoding.Json.destruct Deku_consensus.Block.encoding json - in - Format.eprintf "done!\n%!"; - b + Data_encoding.Json.destruct Deku_consensus.Block.encoding json | None -> Genesis.block in Alcotest.(check' block_testable) ~msg:"hash loaded block is not equal to saved block" ~expected:block ~actual:retrieved_block; + let retrieved_block = + match + Deku_block_storage.Block_storage.find_block_by_level ~level + block_storage + with + | Some json -> + Data_encoding.Json.destruct Deku_consensus.Block.encoding json + | None -> Genesis.block + in + + Alcotest.(check' block_testable) + ~msg:"level loaded block is equal to saved block" ~expected:block + ~actual:retrieved_block; + Eio.Switch.fail sw Test_finished with _ -> () +(* TODO: Add tests with only one env threaded through all tests *) +let eio_test_case : (Eio.Stdenv.t -> unit -> unit) -> unit -> unit = + fun f () -> Eio_main.run (fun env -> f env ()) + let run () = Eio_main.run (fun env -> let open Alcotest in @@ -71,3 +85,8 @@ let run () = ]) let () = run () + +(* TODO: Tests + 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 + try reading something right before you write it and vice versa, + try reading or writing two things at once *)