-
Notifications
You must be signed in to change notification settings - Fork 17
Initial block storage test #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
InfiniteSwerve
wants to merge
5
commits into
main
Choose a base branch
from
block-storage-tests-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4064c9a
added switch.fail to ensure tests finish
InfiniteSwerve f63f836
change block storage to private type
InfiniteSwerve b03e5f3
add test for empty block saving and loading by hash
InfiniteSwerve e5268a5
add random database naming
InfiniteSwerve 89158c4
added level loaded empty block block_storage test
InfiniteSwerve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
deku-p/src/core/block_storage/tests/block_storage_tests.ml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| open Deku_stdlib | ||
| open Deku_crypto | ||
| open Deku_consensus | ||
| open Deku_concepts | ||
|
|
||
| exception Test_finished | ||
|
|
||
| let block_testable = Alcotest.testable Block.pp Block.equal | ||
|
|
||
| let identity = | ||
| let secret = Ed25519.Secret.generate () in | ||
| let secret = Secret.Ed25519 secret in | ||
| Identity.make secret | ||
|
|
||
| let block ~default_block_size = | ||
| let above = Genesis.block in | ||
| let withdrawal_handles_hash = BLAKE2b.hash "potato" in | ||
| let producer = Producer.empty in | ||
| Producer.produce ~identity ~default_block_size ~above ~withdrawal_handles_hash | ||
| producer | ||
|
|
||
| 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 = | ||
| let domains = Eio.Stdenv.domain_mgr env in | ||
| let worker = Parallel.Worker.make ~domains ~sw in | ||
| let storage = Deku_block_storage.Block_storage.make ~worker ~uri in | ||
| storage | ||
|
|
||
| let test_empty_block_load env () = | ||
| try | ||
| Eio.Switch.run @@ fun sw -> | ||
| let block_storage = make_block_storage env sw 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 | ||
| Deku_block_storage.Block_storage.find_block_by_hash ~block_hash:hash | ||
| block_storage | ||
| with | ||
| | Some block -> block | ||
| | 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 block -> block | ||
| | 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 _ -> () | ||
|
|
||
| let run () = | ||
| Eio_main.run (fun env -> | ||
| let open Alcotest in | ||
| run "Block_storage" ~and_exit:false | ||
| [ | ||
| ( "simple", | ||
| [ | ||
| test_case "empty_block is returned" `Quick | ||
| (test_empty_block_load env); | ||
| ] ); | ||
| ]) | ||
|
|
||
| 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 *) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| (executable | ||
| (name block_storage_tests) | ||
| (libraries | ||
| deku_block_storage | ||
| deku_crypto | ||
| deku_protocol | ||
| deku_stdlib | ||
| alcotest | ||
| deku_consensus)) | ||
|
|
||
| (rule | ||
| (alias runtest) | ||
| (deps | ||
| (:exe ./block_storage_tests.exe)) | ||
| (action | ||
| (run %{exe}))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.