Skip to content

Commit ff599ce

Browse files
added 200k block and votes test
fixup: clean tests
1 parent b7b8645 commit ff599ce

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,42 @@ let test_200k_block_load env () =
149149
Eio.Switch.fail sw Test_finished
150150
with _ -> ()
151151

152+
let test_200k_block_and_votes env () =
153+
try
154+
Parallel.Pool.run ~env ~domains:4 @@ fun () ->
155+
Eio.Switch.run @@ fun sw ->
156+
let block_storage = make_block_storage env sw in
157+
let (Block { hash; level; _ } as block) = block ~default_block_size:200_000 in
158+
let vote = make_vote ~hash identity in
159+
let votes = Verified_signature.Set.add vote Verified_signature.Set.empty in
160+
let votes = Verified_signature.Set.elements votes in
161+
let content = Deku_gossip.Message.Content.accepted ~block ~votes in
162+
let (Deku_gossip.Message.Message { header = _; content = _; network }) =
163+
Deku_gossip.Message.encode ~content
164+
in
165+
Block_storage.save_block_and_votes ~level ~network block_storage;
166+
167+
let retrieved_block_and_votes =
168+
let default_return = (Genesis.block, []) in
169+
match Block_storage.find_block_and_votes_by_level ~level block_storage with
170+
| Some (Message.Network.Network_message { raw_header; raw_content }) -> (
171+
let expected = Message.Header.decode ~raw_header in
172+
let (Message.Message { content; _ }) =
173+
Message.decode ~expected ~raw_content
174+
in
175+
match content with
176+
| Content_accepted { block; votes } -> (block, votes)
177+
| _ -> default_return)
178+
| None -> default_return
179+
in
180+
Alcotest.(check' (pair block_testable (list vote_testable)))
181+
~msg:"retrieved empty block and one vote equal saved"
182+
~expected:(block, votes) ~actual:retrieved_block_and_votes;
183+
184+
Eio.Switch.fail sw Test_finished
185+
with _ -> ()
186+
187+
152188
let run () =
153189
Eio_main.run (fun env ->
154190
let open Alcotest in
@@ -162,6 +198,7 @@ let run () =
162198
(test_empty_block_and_votes env);
163199
test_case "200k_block is returned" `Slow
164200
(test_200k_block_load env);
201+
test_case "200k_block_and_votes is returned" `Slow (test_200k_block_and_votes env)
165202
] );
166203
])
167204

0 commit comments

Comments
 (0)