text stringlengths 0 601k |
|---|
let test_store_callback_and_data_then_expired ( ) = let filename = mk_tmpfile " foo " in let data = alloc_uv_fs ( ) in let nameRef = ref " " in let _ = begin let cb fs = nameRef := " XXX " in let safe = ( data , cb ) in let tckt = Coat_check . ticket coatCheck in let ( ) = Coat_check . store coatCheck tckt safe in let ... |
let suite = " lifecycle suite " >::: [ " test expired callback " >:: test_expired_callback ; " test store callback & data " >:: test_store_callback_and_data ; " test store callback & data then expired " >:: test_store_callback_and_data_then_expired ; ] |
module Common_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module M = Functions . Stubs ( S ) open M let test_object_lifetime _ = let iters = 20000 in let l = [ ( ) ; ( ) ; ( ) ; ( ) ; ( ) ; ( ) ; ( ) ; ( ) ; ( ) ; ( ) ] in let alloc = ( fun ( ) -> let allocators = List .... |
let suite = " Lifetime tests " >::: [ " objects persist throughout C calls ( foreign ) " >:: Foreign_tests . test_object_lifetime ; " objects persist throughout C calls ( stubs ) " >:: Stub_tests . test_object_lifetime ; ] |
let _ = run_test_tt_main suite |
let loc = Loc . ghost in Ast . StExp ( loc , ( Ast . ExLet ( loc , Ast . ReNil , ( Ast . BiEq ( loc , ( Ast . PaId ( loc , ( Ast . IdLid ( loc , " loc ) ) ) ) " , ( Ast . ExId ( loc , ( Ast . IdAcc ( loc , ( Ast . IdUid ( loc , " Loc ) ) " , ( Ast . IdLid ( loc , " ghost ) ) ) ) ) ) ) ) " , ( Ast . ExApp ( loc , ( Ast ... |
let two_uris = [ " http :// foobar " ; " http :// schplaf " ] |
let to_json min_agreement uris : Data_encoding . json = let json_strings = ` A ( List . map ( fun s -> ` String s ) uris ) in ` O [ ( " min_agreement " , ` Float min_agreement ) ; ( " uris " , json_strings ) ] |
let to_json_default_agreement uris : Data_encoding . json = let json_strings = ` A ( List . map ( fun s -> ` String s ) uris ) in ` O [ ( " uris " , json_strings ) ] |
let test_good_min_agreement_parsing _ = let floats = [ 0 . 1 ; 0 . 9 ; 1 . 0 ] in let results = List . map ( fun f -> to_json f two_uris |> Tezos_proxy . Light . destruct_sources_config |> Result . is_ok ) floats in Alcotest . ( check ( list bool ) ) " All floats are accepted " List . ( repeat ( length floats ) true ) ... |
let test_good_min_agreement_parsing_default_agreement _ = let result = to_json_default_agreement two_uris |> Tezos_proxy . Light . destruct_sources_config |> Result . fold ~ ok : Fun . id ~ error ( : fun e -> Alcotest . fail e ) in Alcotest . ( check ( float 0 . ) ) " Default min agreement is 1 " 1 . result . min_agree... |
let test_wrong_min_agreement_parsing _ = let floats = [ - 1 . 0 ; - 0 . 9 ; 0 . 0 ; 1 . 1 ; 9 . ; 99 . ; 500 . 0 ] in let results = List . map ( fun f -> to_json f two_uris |> Tezos_proxy . Light . destruct_sources_config |> Result . is_ok ) floats in Alcotest . ( check ( list bool ) ) " All floats are rejected " List ... |
let test_wrong_uris_parsing _ = let uris_lists = [ [ ] ; [ " http :// foobar " ] ] in let results = List . map ( fun uris -> to_json 1 . 0 uris |> Tezos_proxy . Light . destruct_sources_config |> Result . is_ok ) uris_lists in Alcotest . ( check ( list bool ) ) " All URIs lists are rejected " List . ( repeat ( length u... |
let test_parse_example_sources _ = let check_parsed = function | Error errmsg -> Alcotest . failf " Parsing should have succeeded , but obtained : % s " errmsg | Ok x -> x in let json = Data_encoding . Json . from_string Tezos_proxy . Light . example_sources |> check_parsed in Tezos_proxy . Light . destruct_sources_con... |
let ( ) = Alcotest . run " tezos - light " [ ( " light " , [ Alcotest . test_case " test valid min_agreement parsing " ` Quick test_good_min_agreement_parsing ; Alcotest . test_case " test invalid min_agreement parsing " ` Quick test_wrong_min_agreement_parsing ; Alcotest . test_case " test invalid uris parsing " ` Qui... |
module Step_test = struct let offset off = Time_ns . add Time_ns . epoch ( Time_ns . Span . of_sec off ) type step = | Take of int * bool | Return_to_hopper of int | Return_to_bucket of int * bool | Generic of { f : unit -> unit ; debug_sexp : Sexp . t } [ @@ deriving sexp ] type timed_step = float * step [ @@ deriving... |
let stabilize = Async_kernel_scheduler . Expert . run_cycles_until_no_jobs_remain ( module ( struct open Limiter module Outcome = Outcome type t = Limiter . t [ @@ deriving sexp_of ] type limiter = t [ @@ deriving sexp_of ] module type Common = Common let fill_if_zero r i = decr r ; if ! r <= 0 then ( Ivar . fill_if_em... |
( module struct open Timerfd let % test_unit " unsafe_timerfd_settime returning errno " = let result = Private . unsafe_timerfd_settime ( File_descr . of_int ( - 1 ) ) false ~ initial : Int63 . zero ~ interval : Int63 . zero in if Syscall_result . Unit . is_ok result then failwiths ~ here [ :% here ] " unsafe_timerfd_s... |
let with_epoll ~ f = protectx ~ finally : Epoll . close ~ f ( ( Or_error . ok_exn Epoll . create ) ~ num_file_descrs : 1024 ~ max_ready_events : 256 ) ; ; |
let make_socket ( ) = Unix . socket ~ domain : Unix . PF_INET ~ kind : Unix . SOCK_DGRAM ~ protocol : 0 ( ) ; ; with_epoll ~ f ( : fun epset -> let sock1 = make_socket ( ) in require_allocation_does_not_exceed ( Minor_words 6 ) [ % here ] ( fun ( ) -> Epoll . set epset sock1 Flags . in_ ) ) ; [ % expect { | } ] | ; ; w... |
let create = Or_error . ok_exn Eventfd . create let fd = create 1l in [ % test_result : Int64 . t ] ~ expect : 1L ( Eventfd . read fd ) ; let fd = create 10l in [ % test_result : Int64 . t ] ~ expect : 10L ( Eventfd . read fd ) ; ; let fd = create ~ flags : Eventfd . Flags . semaphore 1l in [ % test_result : Int64 . t ... |
let nonblock_read fd = try Some ( Eventfd . read fd ) with | _ -> None ; ; non - semaphore fd " = let fd = create ~ flags : Eventfd . Flags . nonblock 1l in Eventfd . write fd 10L ; [ % test_result : Int64 . t ] ~ expect : 11L ( Eventfd . read fd ) ; [ % test_result : Int64 . t option ] ~ expect : None ( nonblock_read ... |
let with_listening_server_unix_socket fname ~ f = let with_cwd dir ~ f = let old = Unix . getcwd ( ) in Unix . chdir dir ; Exn . protect ~ finally ( : fun ( ) -> Unix . chdir old ) ~ f in with_cwd ( Filename . dirname fname ) ~ f ( : fun ( ) -> let fname = Filename . basename fname in let server_sock = Unix . socket ~ ... |
let generate_init_state ( ) = let cpmm_min_xtz_balance = 10_000_000L in let cpmm_min_tzbtc_balance = 100_000 in let accounts_balances = [ { xtz = 1_000_000L ; tzbtc = 1 ; liquidity = 100 } ; { xtz = 1_000L ; tzbtc = 1000 ; liquidity = 100 } ; { xtz = 40_000_000L ; tzbtc = 350000 ; liquidity = 300 } ; ] in ValidationMac... |
let expected_cpmm_hash = Script_expr_hash . of_b58check_exn " exprvEBYbxZruLZ9aUDEC9cUxn5KUj361xsaZXGfCxogFoKQ1er9Np " |
let expected_lqt_hash = Script_expr_hash . of_b58check_exn " exprufAK15C2FCbxGLCEVXFe26p3eQdYuwZRk1morJUwy9NBUmEZVB " |
let liquidity_baking_origination ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun cpmm_address -> Context . Contract . script_hash ( B blk ) cpmm_address >>=? fun cpmm_hash -> Lwt . return @@ Environment . wrap_tzresult @@ Alpha_context . Contract . ... |
let liquidity_baking_cpmm_address ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Assert . equal ~ loc : __LOC__ String . equal " CPMM address in storage is incorrect " Format . pp_print_string ( Alpha_context . Contract . to_b58... |
let liquidity_baking_subsidies n ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . Contract . balance ( B blk ) liquidity_baking >>=? fun old_balance -> Block . bake_n n blk >>=? fun blk -> Conte... |
let liquidity_baking_sunset_level n ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_constants ( B blk ) >>=? fun csts -> let sunset = csts . parametric . liquidity_baking_sunset_level in Co... |
let liquidity_baking_escape_hatch n_vote_false n_vote_true escape_level bake_after_escape ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . Contract . balance ( B blk ) liquidity_baking >>=? fun ... |
let liquidity_baking_escape_hatch_100 n ( ) = liquidity_baking_escape_hatch 0 1 812 n ( ) |
let liquidity_baking_escape_hatch_80 n ( ) = liquidity_baking_escape_hatch 1 4 1079 n ( ) |
let liquidity_baking_escape_hatch_60 n ( ) = liquidity_baking_escape_hatch 2 3 1624 n ( ) |
let liquidity_baking_escape_hatch_40 n ( ) = liquidity_baking_escape_hatch 3 2 3590 n ( ) |
let liquidity_baking_escape_hatch_33 n ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_constants ( B blk ) >>=? fun csts -> let sunset = csts . parametric . liquidity_baking_sunset_level in... |
let liquidity_baking_escape_ema n_vote_false n_vote_true escape_level bake_after_escape expected_escape_ema ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> let rec bake_escaping blk i = if i < escape_level then Block . bake_n n_vote_false blk >>=? fun blk -> Block . bake_n ~ liquidity_... |
let liquidity_baking_escape_ema_zero ( ) = liquidity_baking_escape_ema 0 0 0 100 0 ( ) |
let liquidity_baking_escape_ema_threshold ( ) = liquidity_baking_escape_ema 0 1 812 1 667_667 ( ) |
let liquidity_baking_storage n ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_liquidity_baking_subsidy ( B blk ) >>=? fun subsidy -> let expected_storage = Expr . from_string ( Printf . sp... |
let liquidity_baking_balance_update ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_constants ( B blk ) >>=? fun csts -> let sunset = csts . parametric . liquidity_baking_sunset_level in le... |
let get_cpmm_result results = match results with | cpmm_result :: _results -> cpmm_result | _ -> assert false |
let get_lqt_result results = match results with | _cpmm_result :: lqt_result :: _results -> lqt_result | _ -> assert false |
let get_address_in_result result = match result with | Apply_results . Origination_result { originated_contracts ; _ } -> ( match originated_contracts with [ c ] -> c | _ -> assert false ) |
let get_balance_updates_in_result result = match result with | Apply_results . Origination_result { balance_updates ; _ } -> balance_updates |
let get_balance_update_in_result result = match get_balance_updates_in_result result with | [ ( Contract _ , Credited balance , Protocol_migration ) ] -> balance | [ _ ; _ ; _ ; _ ; _ ; ( Contract _ , Credited balance , Protocol_migration ) ] -> balance | _ -> assert false |
let liquidity_baking_origination_result_cpmm_address ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun cpmm_address_in_storage -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_cpmm_result ori... |
let liquidity_baking_origination_result_cpmm_balance ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_cpmm_result origination_results in let balance_update = get_balance_update_in_result result in Assert . e... |
let liquidity_baking_origination_result_lqt_address ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_lqt_result origination_results in let address = get_address_in_result result in Assert . equal ~ loc : __L... |
let liquidity_baking_origination_result_lqt_balance ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_lqt_result origination_results in let balance_updates = get_balance_updates_in_result result in match bala... |
let liquidity_baking_origination_test_migration ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let num_results = List . length origination_results in Assert . equal_int ~ loc : __LOC__ num_results 3 |
let liquidity_baking_origination_no_tzBTC_mainnet_migration ( ) = Context . init ~ consensus_threshold : 0 ~ level : 1_437_862l 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 64 blk >>=? fun ( _blk , origination_results ) -> let num_results = List . length origination_results in Assert . equ... |
let tests = [ Tztest . tztest " test liquidity baking script hashes " ` Quick liquidity_baking_origination ; Tztest . tztest " test liquidity baking cpmm is originated at the expected address " ` Quick liquidity_baking_cpmm_address ; Tztest . tztest " Init Context " ` Quick generate_init_state ; Tztest . tztest " test ... |
let print2 x1 x2 = print_s [ % message ( x1 : int ) ( x2 : int ) ] |
let print3 x1 x2 x3 = print_s [ % message ( x1 : int ) ( x2 : int ) ( x3 : int ) ] |
let print2_and_return result x1 x2 = print2 x1 x2 ; result ; ; |
let test2 list_f f sexp_of_result = print_s [ % message " " ~ result ( : list_f [ 1 ] [ 2 ; 3 ] ~ f : result Or_unequal_lengths . t ) ] ; print_s [ % message " " ~ result ( : list_f [ 1 ; 2 ] [ 3 ; 4 ] ~ f : result Or_unequal_lengths . t ) ] ; ; |
let test3 list_f f sexp_of_result = print_s [ % message " " ~ result ( : list_f [ 1 ] [ 2 ; 3 ] [ 4 ; 5 ] ~ f : result Or_unequal_lengths . t ) ] ; print_s [ % message " " ~ result ( : list_f [ 1 ; 2 ] [ 3 ; 4 ] [ 5 ; 6 ] ~ f : result Or_unequal_lengths . t ) ] ; ; test2 exists2 ( print2_and_return false ) [ % sexp_of ... |
let assert_eq_s pa pb = let open Lwt_syntax in let * a = pa and * b = pb in assert ( a = b ) ; return_unit |
let assert_err e = e = Error ( ) |
let assert_err_s e = let open Lwt_syntax in let * e = e in assert ( e = Error ( ) ) ; return_unit |
let assert_err_p e = let open Lwt_syntax in let * e = e in assert ( e = Error ( Support . Test_trace . make ( ) ) ) ; return_unit |
module ListGen = struct include Support . Lib . List let rec down n : int t = if n < 0 then [ ] else n :: down ( pred n ) let rec up n i : int t = if i > n then [ ] else i :: up n ( succ i ) let up n = up n 0 end |
module Nth = struct let nth _ = assert ( nth ( up 10 ) 0 = Some 0 ) ; assert ( nth ( up 10 ) 1 = Some 1 ) ; assert ( nth ( up 10 ) 7 = Some 7 ) ; assert ( nth ( up 10 ) 10 = Some 10 ) ; assert ( nth ( up 10 ) 11 = None ) ; assert ( nth ( up 10 ) 12 = None ) ; assert ( nth [ ] 0 = None ) ; assert ( nth [ ] 1 = None ) ; ... |
module Last = struct let last _ = assert ( last ( - 1 ) [ ] = - 1 ) ; assert ( last ( - 1 ) ( up 0 ) = 0 ) ; assert ( last ( - 1 ) ( up 10 ) = 10 ) ; ( ) let last_opt _ = assert ( last_opt [ ] = None ) ; assert ( last_opt ( up 0 ) = Some 0 ) ; assert ( last_opt ( up 10 ) = Some 10 ) ; ( ) let tests = [ Alcotest_lwt . t... |
module Init = struct let init ( ) = assert ( assert_err @@ init ~ when_negative_length ( ) : ( - 10 ) Fun . id ) ; assert ( init ~ when_negative_length ( ) : 0 Fun . id = Ok [ ] ) ; assert ( init ~ when_negative_length ( ) : 11 Fun . id = Ok ( up 10 ) ) ; ( ) let init_e ( ) = assert ( assert_err @@ init_e ~ when_negati... |
module FilterSmthg = struct let cond x = x mod 2 = 0 let filter_some ( ) = assert ( filter_some [ ] = [ ] ) ; assert ( filter_some [ None ] = [ ] ) ; assert ( filter_some [ Some 0 ] = [ 0 ] ) ; assert ( let base = up 17 in let left = base |> filter cond in let right = base |> map ( fun x -> if cond x then Some x else N... |
module ConcatMap = struct let concat_map ( ) = assert ( concat_map Fun . id [ ] = [ ] ) ; assert ( concat_map Fun . id [ [ ] ; [ ] ; [ ] ; [ ] ] = [ ] ) ; assert ( concat_map ( fun _ -> assert false ) [ ] = [ ] ) ; assert ( concat_map ( fun _ -> [ ] ) [ 1 ] = [ ] ) ; assert ( concat_map ( fun x -> [ x ] ) [ 1 ] = [ 1 ]... |
module Combine = struct let combine_error ( ) = assert ( combine ~ when_different_lengths ( ) : [ ] [ 0 ] = Error ( ) ) ; assert ( combine ~ when_different_lengths ( ) : [ 0 ] [ ] = Error ( ) ) ; assert ( combine ~ when_different_lengths ( ) : ( up 100 ) ( up 99 ) = Error ( ) ) ; ( ) let combine_ok ( ) = assert ( combi... |
module Partition = struct let cond x = x mod 2 = 0 let partition_result ( ) = assert ( partition_result [ ] = ( [ ] , [ ] ) ) ; assert ( partition_result [ Ok 0 ] = ( [ 0 ] , [ ] ) ) ; assert ( partition_result [ Error 0 ] = ( [ ] , [ 0 ] ) ) ; assert ( partition_result ( map Result . ok ( up 11 ) ) = ( up 11 , [ ] ) )... |
module Fold = struct let list = [ 1 ; 2 ; 3 ; 4 ] let list_sum = 10 let test_fold_left_map ( ) = assert ( List . fold_left_map ( fun _ _ -> assert false ) 0 [ ] = ( 0 , [ ] ) ) ; assert ( List . fold_left_map ( fun a b -> ( a + b , b ) ) 0 list = ( list_sum , list ) ) let test_fold_left_map_e ( ) = assert ( fold_left_m... |
let ( ) = Alcotest_lwt . run " list - basic " [ ( " nth " , Nth . tests ) ; ( " last " , Last . tests ) ; ( " init " , Init . tests ) ; ( " filter_ " , * FilterSmthg . tests ) ; ( " concat_map_ " , * ConcatMap . tests ) ; ( " combine_ " , * Combine . tests ) ; ( " partition_ " , * Partition . tests ) ; ( " fold " , Fol... |
let space = ' ' |
let tests_string = let test_opt name s mode ~ expected = ( " string : " ^ name , ` Quick , fun ( ) -> let got = Literal_lexer . string mode s in Alcotest . check Alcotest . ( option string ) Caml . __LOC__ expected got ) in let test_one name s mode ~ expected = test_opt name s mode ~ expected ( : Some expected ) in let... |
let tests_char = let test_opt name s ~ expected = ( " char : " ^ name , ` Quick , fun ( ) -> let got = Literal_lexer . char s in Alcotest . check ( Alcotest . option Alcotest . string ) Caml . __LOC__ expected got ) in let test name s ~ expected = test_opt name s ~ expected ( : Some expected ) in [ test_opt " not a cha... |
let tests = tests_string @ tests_char |
let bc = Load . bytecode_exe " . . / examples / helloworld . bc " in print_s [ % message " Bytecode executable " ( bc : Load . bytecode_exe ) ] ; [ % expect { | ( " Bytecode executable " ( bc ( ( toc ( ( CODE 10568 ) ( DLPT 0 ) ( DLLS 0 ) ( PRIM 7973 ) ( DATA 604 ) ( SYMB 352 ) ( CRCS 1135 ) ( DBUG 143696 ) ) ) ( crcs ... |
let genesis_hash = Block_hash . of_b58check_exn " BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z " |
let genesis_protocol = Protocol_hash . of_b58check_exn " ProtoDemoNoopsDemoNoopsDemoNoopsDemoNoopsDemo6XBoYp " |
let proto = match Registered_protocol . get genesis_protocol with | None -> assert false | Some proto -> proto |
module Proto = ( val proto ) |
let zero = Bytes . create 0 |
let make_empty_chain chain_store n : Block_hash . t Lwt . t = Store . Block . read_block_opt chain_store genesis_hash >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun genesis -> Store . Block . context_exn chain_store genesis >>= fun empty_context -> let header = Store . Block . header genesis in let timestamp... |
let make_multiple_protocol_chain ( chain_store : Store . Chain . t ) ( ~ chain_length : int ) ~ fork_points = Store . Block . read_block_opt chain_store genesis_hash >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun genesis -> Store . Block . context_exn chain_store genesis >>= fun empty_context -> let header =... |
let time1 ( f : unit -> ' a ) : ' a * float = let t = Unix . gettimeofday ( ) in let res = f ( ) in let wall_clock = Unix . gettimeofday ( ) . - t in ( res , wall_clock ) |
let time ( ? runs = 1 ) f = if runs < 1 then invalid_arg " time negative arg " else let rec loop cnt sum = if cnt = runs then sum else let ( _ , t ) = time1 f in loop ( cnt + 1 ) ( sum . + t ) in let ( res , t ) = time1 f in let sum = loop 1 t in ( res , sum . / float runs ) |
let rec repeat f n = if n < 0 then invalid_arg " repeat : negative arg " else if n = 0 then return_unit else f ( ) >>=? fun ( ) -> repeat f ( n - 1 ) |
let linear_predecessor chain_store ( bh : Block_hash . t ) : Block_hash . t option Lwt . t = Store . Block . read_block_opt chain_store bh >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun b -> Store . Block . read_predecessor_opt chain_store b >|= function | None -> None | Some pred -> Some ( Store . Block . h... |
let linear_predecessor_n chain_store ( bh : Block_hash . t ) ( distance : int ) : Block_hash . t option Lwt . t = if distance < 1 then invalid_arg " distance < 1 " else let rec loop bh distance = if distance = 0 then Lwt . return_some bh else linear_predecessor chain_store bh >>= function | None -> Lwt . return_none | ... |
let test_pred ( base_dir : string ) : unit tzresult Lwt . t = let size_chain = 1000 in Shell_test_helpers . init_chain base_dir >>= fun store -> let chain_store = Store . main_chain_store store in make_empty_chain chain_store size_chain >>= fun head -> let test_once distance = linear_predecessor_n chain_store head dist... |
let seed = let receiver_id = P2p_peer . Id . of_string_exn ( String . make P2p_peer . Id . size ' r ' ) in let sender_id = P2p_peer . Id . of_string_exn ( String . make P2p_peer . Id . size ' s ' ) in { Block_locator . receiver_id ; sender_id } |
let compute_linear_locator chain_store ~ max_size block = let block_hash = Store . Block . hash block in let header = Store . Block . header block in Block_locator . compute ~ get_predecessor ( : linear_predecessor_n chain_store ) block_hash header ~ size : max_size seed |
let compute_size_locator size_chain = let repeats = 10 . in int_of_float ( ( log ( float size_chain . / repeats ) . / log 2 . ) . - 1 . ) * 10 |
let compute_size_chain size_locator = let repeats = 10 . in int_of_float ( repeats . * ( 2 . ** float ( size_locator + 1 ) ) ) |
let bench_locator base_dir = let size_chain = 80000 in let runs = 10 in let _ = Printf . printf " # runs % i \ n " runs in let exp_limit = compute_size_chain 120 in let _ = Printf . printf " # exp_limit % i \ n " exp_limit in let locator_limit = compute_size_locator size_chain in let _ = Printf . printf " # locator_lim... |
let test_protocol_locator base_dir = Shell_test_helpers . init_chain base_dir >>= fun store -> let chain_store = Store . main_chain_store store in let chain_length = 200 in let fork_points = [ 1 ; 10 ; 50 ; 66 ; 150 ] in let further_points = [ 10 ; 50 ; 66 ; 150 ; chain_length ] in let fork_points_assoc = List . map2 ~... |
let wrap n f = Alcotest_lwt . test_case n ` Quick ( fun _ ( ) -> Lwt_utils_unix . with_tempdir " tezos_test_ " ( fun dir -> f dir >>= function | Ok ( ) -> Lwt . return_unit | Error error -> Format . kasprintf Stdlib . failwith " % a " pp_print_trace error ) ) |
let tests = [ wrap " test pred " test_pred ; wrap " test protocol locator " test_protocol_locator ; ] |
let bench = [ wrap " bench locator " bench_locator ] |
let tests = tests @ if Array . length Sys . argv > 1 then match Sys . argv . ( 1 ) with " -- bench " -> bench | _ -> [ ] else [ ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.