Skip to content

Commit f539707

Browse files
added 200k block and votes test
fixup: clean tests
1 parent 6c0515c commit f539707

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,44 @@ let test_200k_block_load env () =
142142
Eio.Switch.fail sw Test_finished
143143
with _ -> ()
144144

145+
let test_200k_block_and_votes env () =
146+
try
147+
Eio.Switch.run @@ fun sw ->
148+
let block_storage = make_block_storage env sw in
149+
let (Block { hash; level; _ } as block) =
150+
block ~default_block_size:200_000
151+
in
152+
let vote = make_vote ~hash identity in
153+
let votes = Verified_signature.Set.add vote Verified_signature.Set.empty in
154+
let votes = Verified_signature.Set.elements votes in
155+
let content = Deku_gossip.Message.Content.accepted ~block ~votes in
156+
let (Deku_gossip.Message.Message { header = _; content = _; network }) =
157+
Deku_gossip.Message.encode ~content
158+
in
159+
Block_storage.save_block_and_votes ~level ~network block_storage;
160+
161+
let retrieved_block_and_votes =
162+
let default_return = (Genesis.block, []) in
163+
match
164+
Block_storage.find_block_and_votes_by_level ~level block_storage
165+
with
166+
| Some (Message.Network.Network_message { raw_header; raw_content }) -> (
167+
let expected = Message.Header.decode ~raw_header in
168+
let (Message.Message { content; _ }) =
169+
Message.decode ~expected ~raw_content
170+
in
171+
match content with
172+
| Content_accepted { block; votes } -> (block, votes)
173+
| _ -> default_return)
174+
| None -> default_return
175+
in
176+
Alcotest.(check' (pair block_testable (list vote_testable)))
177+
~msg:"retrieved empty block and one vote equal saved"
178+
~expected:(block, votes) ~actual:retrieved_block_and_votes;
179+
180+
Eio.Switch.fail sw Test_finished
181+
with _ -> ()
182+
145183
let run () =
146184
Eio_main.run (fun env ->
147185
let open Alcotest in
@@ -155,6 +193,8 @@ let run () =
155193
(test_empty_block_and_votes env);
156194
test_case "200k_block is returned" `Slow
157195
(test_200k_block_load env);
196+
test_case "200k_block_and_votes is returned" `Slow
197+
(test_200k_block_and_votes env);
158198
] );
159199
])
160200

0 commit comments

Comments
 (0)