2016-10-12 17:00:19 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-10-12 17:00:19 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
open Store
|
|
|
|
|
|
|
|
let (>>=) = Lwt.bind
|
|
|
|
let (>|=) = Lwt.(>|=)
|
|
|
|
let (//) = Filename.concat
|
|
|
|
|
|
|
|
(** Basic blocks *)
|
|
|
|
|
|
|
|
let genesis_block =
|
2017-04-05 11:54:21 +04:00
|
|
|
Block_hash.of_b58check_exn
|
2017-02-19 21:22:32 +04:00
|
|
|
"BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let genesis_protocol =
|
2017-04-05 11:54:21 +04:00
|
|
|
Protocol_hash.of_b58check_exn
|
2017-02-19 21:22:32 +04:00
|
|
|
"ProtoDemoDemoDemoDemoDemoDemoDemoDemoDemoDemoD3c8k9"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let genesis_time =
|
|
|
|
Time.of_seconds 0L
|
|
|
|
|
|
|
|
let genesis = {
|
2017-02-24 20:17:53 +04:00
|
|
|
State.Net.time = genesis_time ;
|
2016-09-08 21:13:10 +04:00
|
|
|
block = genesis_block ;
|
|
|
|
protocol = genesis_protocol ;
|
|
|
|
}
|
|
|
|
|
|
|
|
(** *)
|
|
|
|
|
|
|
|
let wrap_store_init f base_dir =
|
|
|
|
let root = base_dir // "store" in
|
2017-02-24 20:17:53 +04:00
|
|
|
Store.init root >>= function
|
2017-03-07 12:51:11 +04:00
|
|
|
| Ok store ->
|
|
|
|
f store >>= fun () ->
|
|
|
|
return ()
|
2017-02-24 20:17:53 +04:00
|
|
|
| Error err ->
|
|
|
|
Format.kasprintf Pervasives.failwith
|
|
|
|
"@[Cannot initialize store:@ %a@]" pp_print_error err
|
|
|
|
|
|
|
|
let wrap_raw_store_init f base_dir =
|
|
|
|
let root = base_dir // "store" in
|
|
|
|
Raw_store.init root >>= function
|
2017-03-07 12:51:11 +04:00
|
|
|
| Ok store ->
|
|
|
|
f store >>= fun () ->
|
|
|
|
return ()
|
2017-02-24 20:17:53 +04:00
|
|
|
| Error err ->
|
|
|
|
Format.kasprintf Pervasives.failwith
|
|
|
|
"@[Cannot initialize store:@ %a@]" pp_print_error err
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let test_init _ = Lwt.return_unit
|
|
|
|
|
2017-03-31 15:04:05 +04:00
|
|
|
let net_id = Net_id.of_block_hash genesis_block
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
(** Operation store *)
|
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let make proto : Operation.t =
|
2017-11-14 05:41:37 +04:00
|
|
|
{ shell = { branch = genesis_block } ; proto }
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let op1 = make (MBytes.of_string "Capadoce")
|
2017-11-27 09:13:12 +04:00
|
|
|
let oph1 = Operation.hash op1
|
2016-09-08 21:13:10 +04:00
|
|
|
let op2 = make (MBytes.of_string "Kivu")
|
2017-11-27 09:13:12 +04:00
|
|
|
let oph2 = Operation.hash op2
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
|
|
|
|
(** Block store *)
|
|
|
|
|
|
|
|
let lolblock ?(operations = []) header =
|
2017-04-10 19:06:11 +04:00
|
|
|
let operations_hash =
|
2017-03-30 15:16:21 +04:00
|
|
|
Operation_list_list_hash.compute
|
|
|
|
[Operation_list_hash.compute operations] in
|
2017-04-19 23:46:10 +04:00
|
|
|
{ Store.Block.header =
|
|
|
|
{ Block_header.shell =
|
|
|
|
{ timestamp = Time.of_seconds (Random.int64 1500L) ;
|
|
|
|
level = 0l ; (* dummy *)
|
|
|
|
proto_level = 0 ; (* dummy *)
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes = Random.int 32 ;
|
2017-04-19 23:46:10 +04:00
|
|
|
predecessor = genesis_block ; operations_hash ;
|
|
|
|
fitness = [MBytes.of_string @@ string_of_int @@ String.length header;
|
2017-12-05 18:19:22 +04:00
|
|
|
MBytes.of_string @@ string_of_int @@ 12] ;
|
|
|
|
context = Context_hash.zero } ;
|
2017-04-19 23:46:10 +04:00
|
|
|
proto = MBytes.of_string header ;
|
|
|
|
} ;
|
2017-04-18 13:29:14 +04:00
|
|
|
max_operations_ttl = 0 ;
|
2017-12-05 18:18:05 +04:00
|
|
|
message = None ;
|
2017-12-05 18:17:54 +04:00
|
|
|
context = Context_hash.zero ;
|
2017-11-19 17:38:36 +04:00
|
|
|
max_operation_data_length = 0 ;
|
2016-09-08 21:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let b1 = lolblock "Blop !"
|
2017-04-19 23:46:10 +04:00
|
|
|
let bh1 = Block_header.hash b1.header
|
2016-09-08 21:13:10 +04:00
|
|
|
let b2 = lolblock "Tacatlopo"
|
2017-04-19 23:46:10 +04:00
|
|
|
let bh2 = Block_header.hash b2.header
|
2016-09-08 21:13:10 +04:00
|
|
|
let b3 = lolblock ~operations:[oph1;oph2] "Persil"
|
2017-04-19 23:46:10 +04:00
|
|
|
let bh3 = Block_header.hash b3.header
|
2016-10-06 20:30:04 +04:00
|
|
|
let bh3' =
|
2016-11-25 22:46:50 +04:00
|
|
|
let raw = Bytes.of_string @@ Block_hash.to_string bh3 in
|
2016-10-06 20:30:04 +04:00
|
|
|
Bytes.set raw 31 '\000' ;
|
|
|
|
Bytes.set raw 30 '\000' ;
|
2017-02-24 20:17:53 +04:00
|
|
|
Block_hash.of_string_exn @@ Bytes.to_string raw
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let equal (b1: Store.Block.contents) (b2: Store.Block.contents) =
|
|
|
|
Block_header.equal b1.header b2.header &&
|
2017-09-29 20:43:13 +04:00
|
|
|
b1.message = b2.message
|
2017-04-19 23:46:10 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
let check_block s h b =
|
2017-04-19 23:46:10 +04:00
|
|
|
Store.Block.Contents.read (s, h) >>= function
|
|
|
|
| Ok b' when equal b b' -> Lwt.return_unit
|
|
|
|
| Ok _ ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Printf.eprintf "Error while reading block %s\n%!" (Block_hash.to_hex h);
|
|
|
|
exit 1
|
2017-04-19 23:46:10 +04:00
|
|
|
| Error err ->
|
|
|
|
Format.eprintf "@[Error while reading block %s:@ %a\n@]"
|
|
|
|
(Block_hash.to_hex h)
|
|
|
|
pp_print_error err;
|
2016-09-08 21:13:10 +04:00
|
|
|
exit 1
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let test_block s =
|
|
|
|
let s = Store.Net.get s net_id in
|
2017-04-19 23:46:10 +04:00
|
|
|
let s = Store.Block.get s in
|
|
|
|
Block.Contents.store (s, bh1) b1 >>= fun () ->
|
|
|
|
Block.Contents.store (s, bh2) b2 >>= fun () ->
|
|
|
|
Block.Contents.store (s, bh3) b3 >>= fun () ->
|
2017-02-24 20:17:53 +04:00
|
|
|
check_block s bh1 b1 >>= fun () ->
|
|
|
|
check_block s bh2 b2 >>= fun () ->
|
|
|
|
check_block s bh3 b3
|
|
|
|
|
|
|
|
let test_expand s =
|
|
|
|
let s = Store.Net.get s net_id in
|
2017-04-19 23:46:10 +04:00
|
|
|
let s = Store.Block.get s in
|
|
|
|
Block.Contents.store (s, bh1) b1 >>= fun () ->
|
|
|
|
Block.Contents.store (s, bh2) b2 >>= fun () ->
|
|
|
|
Block.Contents.store (s, bh3) b3 >>= fun () ->
|
|
|
|
Block.Contents.store (s, bh3') b3 >>= fun () ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Base58.complete (Block_hash.to_short_b58check bh1) >>= fun res ->
|
|
|
|
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b58check bh1] ;
|
|
|
|
Base58.complete (Block_hash.to_short_b58check bh2) >>= fun res ->
|
|
|
|
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b58check bh2] ;
|
|
|
|
Base58.complete (Block_hash.to_short_b58check bh3) >>= fun res ->
|
2017-03-30 19:19:59 +04:00
|
|
|
Assert.equal_string_list ~msg:__LOC__
|
|
|
|
(List.sort String.compare res)
|
|
|
|
[Block_hash.to_b58check bh3' ; Block_hash.to_b58check bh3] ;
|
2017-02-24 20:17:53 +04:00
|
|
|
Lwt.return_unit
|
2016-10-06 20:30:04 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** Generic store *)
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let check (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) k d =
|
|
|
|
Store.read_opt s k >|= fun d' ->
|
2016-09-08 21:13:10 +04:00
|
|
|
if d' <> Some d then begin
|
2016-09-30 13:43:50 +04:00
|
|
|
Assert.fail_msg
|
|
|
|
"Error while reading key %S\n%!" (String.concat Filename.dir_sep k) ;
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let check_none (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) k =
|
|
|
|
Store.read_opt s k >|= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| None -> ()
|
|
|
|
| Some _ ->
|
2016-09-30 13:43:50 +04:00
|
|
|
Assert.fail_msg
|
2016-09-08 21:13:10 +04:00
|
|
|
"Error while reading non-existent key %S\n%!"
|
|
|
|
(String.concat Filename.dir_sep k)
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let test_generic (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) =
|
|
|
|
Store.store s ["day";"current"] (MBytes.of_string "Mercredi") >>= fun () ->
|
|
|
|
Store.store s ["day";"next"] (MBytes.of_string "Jeudi") >>= fun () ->
|
|
|
|
Store.store s ["day";"truc";"chose"] (MBytes.of_string "Vendredi") >>= fun () ->
|
|
|
|
check (module Store) s ["day";"current"] (MBytes.of_string "Mercredi") >>= fun () ->
|
|
|
|
check (module Store) s ["day";"next"] (MBytes.of_string "Jeudi") >>= fun () ->
|
|
|
|
check_none (module Store) s ["day"]
|
|
|
|
|
|
|
|
let list (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) k =
|
|
|
|
Store.fold_keys s k ~init:[] ~f:(fun k acc -> Lwt.return (k :: acc))
|
|
|
|
|
|
|
|
let test_generic_list (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) =
|
|
|
|
Store.store s ["a"; "b"] (MBytes.of_string "Novembre") >>= fun () ->
|
|
|
|
Store.store s ["a"; "c"] (MBytes.of_string "Juin") >>= fun () ->
|
|
|
|
Store.store s ["a"; "d"; "e"] (MBytes.of_string "Septembre") >>= fun () ->
|
|
|
|
Store.store s ["f";] (MBytes.of_string "Avril") >>= fun () ->
|
|
|
|
Store.store s ["g"; "h"] (MBytes.of_string "Avril") >>= fun () ->
|
|
|
|
list (module Store) s [] >>= fun l ->
|
2017-04-05 20:24:26 +04:00
|
|
|
Assert.equal_string_list_list ~msg:__LOC__
|
2017-02-24 20:17:53 +04:00
|
|
|
[["a";"b"];["a";"c"];["a";"d";"e"];["f"];["g";"h"]]
|
|
|
|
(List.sort compare l) ;
|
|
|
|
list (module Store) s ["a"] >>= fun l ->
|
2017-04-05 20:24:26 +04:00
|
|
|
Assert.equal_string_list_list
|
2017-02-24 20:17:53 +04:00
|
|
|
~msg:__LOC__ [["a";"b"]; ["a";"c"]; ["a";"d";"e"]]
|
|
|
|
(List.sort compare l) ;
|
|
|
|
list (module Store) s ["f"] >>= fun l ->
|
2017-04-05 20:24:26 +04:00
|
|
|
Assert.equal_string_list_list ~msg:__LOC__ [] l ;
|
2017-02-24 20:17:53 +04:00
|
|
|
list (module Store) s ["g"] >>= fun l ->
|
2017-04-05 20:24:26 +04:00
|
|
|
Assert.equal_string_list_list ~msg:__LOC__ [["g";"h"]] (List.sort compare l) ;
|
2017-02-24 20:17:53 +04:00
|
|
|
list (module Store) s ["i"] >>= fun l ->
|
2017-04-05 20:24:26 +04:00
|
|
|
Assert.equal_string_list_list ~msg:__LOC__ [] l ;
|
2017-02-24 20:17:53 +04:00
|
|
|
Lwt.return_unit
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** HashSet *)
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
open Store_helpers
|
|
|
|
|
|
|
|
let test_hashset (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) =
|
|
|
|
let module BlockSet = Block_hash.Set in
|
2016-09-08 21:13:10 +04:00
|
|
|
let module StoreSet =
|
2017-02-24 20:17:53 +04:00
|
|
|
Make_buffered_set
|
|
|
|
(Make_substore(Store)(struct let name = ["test_set"] end))
|
|
|
|
(Block_hash)
|
|
|
|
(BlockSet) in
|
2016-09-30 13:43:50 +04:00
|
|
|
let bhset : BlockSet.t = BlockSet.add bh2 (BlockSet.add bh1 BlockSet.empty) in
|
2017-02-24 20:17:53 +04:00
|
|
|
StoreSet.store_all s bhset >>= fun () ->
|
|
|
|
StoreSet.read_all s >>= fun bhset' ->
|
|
|
|
Assert.equal_block_set ~msg:__LOC__ bhset bhset' ;
|
|
|
|
let bhset2 =
|
|
|
|
Pervasives.(bhset |> BlockSet.add bh3 |> BlockSet.remove bh1) in
|
|
|
|
StoreSet.store_all s bhset2 >>= fun () ->
|
|
|
|
StoreSet.read_all s >>= fun bhset2' ->
|
|
|
|
Assert.equal_block_set ~msg:__LOC__ bhset2 bhset2' ;
|
2017-11-13 17:29:28 +04:00
|
|
|
StoreSet.fold s ~init:BlockSet.empty
|
|
|
|
~f:(fun bh acc -> Lwt.return (BlockSet.add bh acc)) >>= fun bhset2'' ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Assert.equal_block_set ~msg:__LOC__ bhset2 bhset2'' ;
|
|
|
|
Store.store s ["day";"current"] (MBytes.of_string "Mercredi") >>= fun () ->
|
|
|
|
StoreSet.remove_all s >>= fun () ->
|
|
|
|
StoreSet.read_all s >>= fun empty ->
|
|
|
|
Assert.equal_block_set ~msg:__LOC__ BlockSet.empty empty ;
|
|
|
|
check (module Store) s ["day";"current"] (MBytes.of_string "Mercredi") >>= fun () ->
|
|
|
|
Lwt.return_unit
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
|
|
|
|
(** HashMap *)
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let test_hashmap (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) =
|
|
|
|
let module BlockMap = Block_hash.Map in
|
2016-09-08 21:13:10 +04:00
|
|
|
let module StoreMap =
|
2017-02-24 20:17:53 +04:00
|
|
|
Make_buffered_map
|
|
|
|
(Make_substore(Store)(struct let name = ["test_map"] end))
|
|
|
|
(Block_hash)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = int * char
|
|
|
|
let encoding =
|
|
|
|
Data_encoding.(tup2 int31 (conv int_of_char char_of_int int8))
|
|
|
|
end))
|
2016-09-08 21:13:10 +04:00
|
|
|
(BlockMap) in
|
2017-02-24 20:17:53 +04:00
|
|
|
let eq = (=) in
|
2016-09-08 21:13:10 +04:00
|
|
|
let map =
|
2016-09-30 13:43:50 +04:00
|
|
|
Pervasives.(BlockMap.empty |>
|
|
|
|
BlockMap.add bh1 (1, 'a') |> BlockMap.add bh2 (2, 'b')) in
|
2017-02-24 20:17:53 +04:00
|
|
|
StoreMap.store_all s map >>= fun () ->
|
|
|
|
StoreMap.read_all s >>= fun map' ->
|
|
|
|
Assert.equal_block_map ~msg:__LOC__ ~eq map map' ;
|
|
|
|
let map2 =
|
|
|
|
Pervasives.(map |> BlockMap.add bh3 (3, 'c') |> BlockMap.remove bh1) in
|
|
|
|
StoreMap.store_all s map2 >>= fun () ->
|
|
|
|
StoreMap.read_all s >>= fun map2' ->
|
|
|
|
Assert.equal_block_map ~msg:__LOC__ ~eq map2 map2' ;
|
|
|
|
Lwt.return_unit
|
|
|
|
|
|
|
|
(** Functors *)
|
|
|
|
|
|
|
|
let test_single (type t)
|
|
|
|
(module Store: Store_sigs.STORE with type t = t) (s: Store.t) =
|
|
|
|
let module Single =
|
|
|
|
Make_single_store
|
|
|
|
(Store)
|
|
|
|
(struct let name = ["plop"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = int * string
|
|
|
|
let encoding = Data_encoding.(tup2 int31 string)
|
|
|
|
end)) in
|
|
|
|
Single.known s >>= fun known ->
|
|
|
|
Assert.is_false ~msg:__LOC__ known ;
|
|
|
|
Single.read_opt s >>= fun v' ->
|
|
|
|
Assert.equal ~msg:__LOC__ None v' ;
|
|
|
|
let v = (3, "Non!") in
|
|
|
|
Single.store s v >>= fun () ->
|
|
|
|
Single.known s >>= fun known ->
|
|
|
|
Assert.is_true ~msg:__LOC__ known ;
|
|
|
|
Single.read_opt s >>= fun v' ->
|
|
|
|
Assert.equal ~msg:__LOC__ (Some v) v' ;
|
2017-04-05 20:24:26 +04:00
|
|
|
Single.remove s >>= fun () ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Single.known s >>= fun known ->
|
|
|
|
Assert.is_false ~msg:__LOC__ known ;
|
|
|
|
Single.read_opt s >>= fun v' ->
|
|
|
|
Assert.equal ~msg:__LOC__ None v' ;
|
|
|
|
Lwt.return_unit
|
|
|
|
|
|
|
|
module Sub =
|
|
|
|
Make_substore(Raw_store)(struct let name = ["plop";"plip"] end)
|
|
|
|
|
|
|
|
module SubBlocks =
|
|
|
|
Make_indexed_substore
|
|
|
|
(Make_substore(Raw_store)(struct let name = ["blocks"] end))
|
|
|
|
(Block_hash)
|
|
|
|
|
|
|
|
module SubBlocksSet =
|
|
|
|
SubBlocks.Make_buffered_set
|
|
|
|
(struct let name = ["test_set"] end)
|
|
|
|
(Block_hash.Set)
|
|
|
|
|
|
|
|
module SubBlocksMap =
|
|
|
|
SubBlocks.Make_buffered_map
|
|
|
|
(struct let name = ["test_map"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = int * string
|
|
|
|
let encoding = Data_encoding.(tup2 int31 string)
|
|
|
|
end))
|
|
|
|
(Block_hash.Map)
|
|
|
|
|
|
|
|
let test_subblock s =
|
|
|
|
SubBlocksSet.known s bh1 >>= fun known ->
|
|
|
|
Assert.is_false ~msg:__LOC__ known ;
|
|
|
|
SubBlocksSet.store s bh1 >>= fun () ->
|
|
|
|
SubBlocksSet.store s bh2 >>= fun () ->
|
|
|
|
SubBlocksSet.known s bh2 >>= fun known ->
|
|
|
|
Assert.is_true ~msg:__LOC__ known ;
|
|
|
|
SubBlocksSet.read_all s >>= fun set ->
|
|
|
|
let set' =
|
|
|
|
Block_hash.Set.empty
|
|
|
|
|> Block_hash.Set.add bh1
|
|
|
|
|> Block_hash.Set.add bh2 in
|
|
|
|
Assert.equal_block_set ~msg:__LOC__ set set' ;
|
|
|
|
SubBlocksSet.remove s bh2 >>= fun () ->
|
|
|
|
let set =
|
|
|
|
Block_hash.Set.empty
|
|
|
|
|> Block_hash.Set.add bh3'
|
|
|
|
|> Block_hash.Set.add bh3 in
|
|
|
|
SubBlocksSet.store_all s set >>= fun () ->
|
|
|
|
SubBlocksSet.elements s >>= fun elts ->
|
|
|
|
Assert.equal_block_hash_list ~msg:__LOC__
|
|
|
|
(List.sort Block_hash.compare elts)
|
|
|
|
(List.sort Block_hash.compare [bh3 ; bh3']) ;
|
|
|
|
SubBlocksSet.store s bh2 >>= fun () ->
|
|
|
|
SubBlocksSet.remove s bh3 >>= fun () ->
|
|
|
|
SubBlocksSet.elements s >>= fun elts ->
|
|
|
|
Assert.equal_block_hash_list ~msg:__LOC__
|
|
|
|
(List.sort Block_hash.compare elts)
|
|
|
|
(List.sort Block_hash.compare [bh2 ; bh3']) ;
|
|
|
|
SubBlocksMap.known s bh1 >>= fun known ->
|
|
|
|
Assert.is_false ~msg:__LOC__ known ;
|
|
|
|
let v1 = (3, "Non!")
|
|
|
|
and v2 = (12, "Beurk.") in
|
|
|
|
SubBlocksMap.store s bh1 v1 >>= fun () ->
|
|
|
|
SubBlocksMap.store s bh2 v2 >>= fun () ->
|
|
|
|
SubBlocksMap.known s bh1 >>= fun known ->
|
2017-04-05 20:24:26 +04:00
|
|
|
SubBlocksMap.read_opt s bh1 >>= fun v1' ->
|
|
|
|
Assert.equal ~msg:__LOC__ (Some v1) v1' ;
|
2017-02-24 20:17:53 +04:00
|
|
|
Assert.is_true ~msg:__LOC__ known ;
|
|
|
|
let map =
|
|
|
|
Block_hash.Map.empty
|
|
|
|
|> Block_hash.Map.add bh1 v1
|
|
|
|
|> Block_hash.Map.add bh2 v2 in
|
|
|
|
SubBlocksMap.read_all s >>= fun map' ->
|
|
|
|
Assert.equal_block_map ~eq:(=) ~msg:__LOC__ map map' ;
|
|
|
|
|
|
|
|
SubBlocksSet.remove_all s >>= fun () ->
|
|
|
|
SubBlocksSet.elements s >>= fun elts ->
|
|
|
|
Assert.equal_block_hash_list ~msg:__LOC__ elts [] ;
|
|
|
|
|
|
|
|
SubBlocksMap.read_all s >>= fun map' ->
|
|
|
|
Assert.equal_block_map ~eq:(=) ~msg:__LOC__ map map' ;
|
|
|
|
|
|
|
|
SubBlocksSet.store s bh3 >>= fun () ->
|
|
|
|
|
|
|
|
SubBlocks.indexes s >>= fun keys ->
|
|
|
|
Assert.equal_block_hash_list ~msg:__LOC__
|
|
|
|
(List.sort Block_hash.compare keys)
|
|
|
|
(List.sort Block_hash.compare [bh1;bh2;bh3]) ;
|
|
|
|
|
|
|
|
Lwt.return_unit
|
|
|
|
|
|
|
|
module SubSubBlocks =
|
|
|
|
Make_indexed_substore
|
|
|
|
(Make_substore(SubBlocks.Store)(struct let name = ["sub_blocks"] end))
|
|
|
|
(Block_hash)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** *)
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let tests_raw : (string * (Raw_store.t -> unit Lwt.t)) list = [
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
"init", test_init ;
|
2017-02-24 20:17:53 +04:00
|
|
|
|
|
|
|
"generic", test_generic (module Raw_store) ;
|
|
|
|
"generic_substore", test_generic (module Sub) ;
|
|
|
|
"generic_indexedstore",
|
|
|
|
(fun s -> test_generic (module SubBlocks.Store) (s, bh1)) ;
|
|
|
|
"generic_indexedsubstore",
|
|
|
|
(fun s -> test_generic (module SubSubBlocks.Store) ((s, bh1), bh2)) ;
|
|
|
|
|
|
|
|
"single", test_single (module Raw_store) ;
|
|
|
|
"single_substore", test_single (module Sub) ;
|
|
|
|
"single_indexedstore",
|
|
|
|
(fun s -> test_single (module SubBlocks.Store) (s, bh1)) ;
|
|
|
|
"single_indexedsubstore",
|
|
|
|
(fun s -> test_single (module SubSubBlocks.Store) ((s, bh1), bh2)) ;
|
|
|
|
|
|
|
|
"generic_list", test_generic_list (module Raw_store);
|
|
|
|
"generic_substore_list", test_generic_list (module Sub);
|
|
|
|
"generic_indexedstore_list",
|
|
|
|
(fun s -> test_generic_list (module SubBlocks.Store) (s, bh1));
|
|
|
|
"generic_indexedsubstore_list",
|
|
|
|
(fun s -> test_generic_list (module SubSubBlocks.Store) ((s, bh1), bh2)) ;
|
|
|
|
|
|
|
|
"hashset", test_hashset (module Raw_store) ;
|
|
|
|
"hashset_substore", test_hashset (module Sub) ;
|
|
|
|
"hashset_indexedstore",
|
|
|
|
(fun s -> test_hashset (module SubBlocks.Store) (s, bh1));
|
|
|
|
"hashset_indexedsubstore",
|
|
|
|
(fun s -> test_hashset (module SubSubBlocks.Store) ((s, bh1), bh2)) ;
|
|
|
|
|
|
|
|
"hashmap", test_hashmap (module Raw_store) ;
|
|
|
|
"hashmap_substore", test_hashmap (module Sub) ;
|
|
|
|
"hashmap_indexedstore",
|
|
|
|
(fun s -> test_hashmap (module SubBlocks.Store) (s, bh1));
|
|
|
|
"hashmap_indexedsubstore",
|
|
|
|
(fun s -> test_hashmap (module SubSubBlocks.Store) ((s, bh1), bh2)) ;
|
|
|
|
|
|
|
|
"subblock", test_subblock ;
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
let tests : (string * (Store.t -> unit Lwt.t)) list = [
|
2017-03-30 19:19:59 +04:00
|
|
|
"expand", test_expand ;
|
2016-09-08 21:13:10 +04:00
|
|
|
"block", test_block ;
|
2016-09-30 13:43:50 +04:00
|
|
|
]
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-09-30 13:43:50 +04:00
|
|
|
let () =
|
2017-02-24 20:17:53 +04:00
|
|
|
Test.run "store."
|
|
|
|
(List.map (fun (s, f) -> s, wrap_raw_store_init f) tests_raw @
|
|
|
|
List.map (fun (s, f) -> s, wrap_store_init f) tests)
|