text
stringlengths
0
601k
let test_inconsistent_counters ( ) = Context . init 2 >>=? fun ( blk , contracts ) -> let ( c1 , c2 ) = match contracts with [ c1 ; c2 ] -> ( c1 , c2 ) | _ -> assert false in Op . transaction ~ gas_limit ~ fee : Tez . one ( B blk ) c1 c2 Tez . one >>=? fun op1 -> Op . transaction ~ gas_limit ~ fee : Tez . one ( B blk )...
let tests = [ Tztest . tztest " multiple transfers " ` Quick test_multiple_transfers ; Tztest . tztest " multiple originations and delegations " ` Quick test_multiple_origination_and_delegation ; Tztest . tztest " Failing operation in the middle " ` Quick test_failing_operation_in_the_middle ; Tztest . tztest " Failing...
let is_command value = print_s [ % sexp ( Value . is_command value : bool ) ] let f = Symbol . gensym ( ) in defun f [ % here ] ~ docstring " :< docstring " > ~ interactive : Raw_prefix ( Returns Value . Type . unit ) ( let open Defun . Let_syntax in let % map_open arg = required " arg " value in print_s [ % message " ...
let give_emacs_chance_to_signal ( ) = ignore ( Text . of_utf8_bytes " ignoreme " : Text . t ) show_raise ( fun ( ) -> Command . request_quit ( ) ; give_emacs_chance_to_signal ( ) ) ; [ % expect { | ( raised quit ) } ] ; | return ( ) ; ; show_raise ( fun ( ) -> Current_buffer . set_value_temporarily Sync inhibit_quit tr...
module Command_making_state = struct type specific = < env_config : Environment_configuration . t ; command_name : string ; manpager : Manpage_builder . State . t > type ' a t = ' a Base_state . t constraint ' a = < specific ; . . > let make ~ application_name ~ command_name ( ) : _ t = let env_config = Environment_con...
module Common_errors = struct type t = [ ` Die of int | ` Empty_protocol_list | ` Precheck_failure of string | Process_result . Error . t | ` Scenario_error of string | System_error . t | Test_scenario . Inconsistency_error . t | ` Waiting_for of string * [ ` Time_out ] ] let pp ppf ( e : t ) = match e with | ` Scenari...
module Run_command = struct let or_hard_fail state main ~ pp_error : unit = let open Asynchronous_result in Dbg . e EF . ( wf " Run_command . or_hard_fail " ) ; run_application ( fun ( ) -> Dbg . e EF . ( wf " Run_command . or_hard_fail bind_on_error " ) ; bind_on_error ( main ( ) ) ~ f ( : fun ~ result _ -> Dbg . e EF...
module Full_default_state = struct let cmdliner_term base_state ? default_interactivity ( ? disable_interactivity = false ) ( ) = let runner = Running_processes . State . make ( ) in let default_root = sprintf " / tmp /% s - test " base_state # command_name in let pauser = Interactive_test . Pauser . make [ ] in let op...
let cli_state ? default_interactivity ? disable_interactivity ~ name ( ) = let application_name = Fmt . str " Flextesa . % s " name in let command_name = name in let base_state = Command_making_state . make ~ application_name ~ command_name ( ) in Full_default_state . cmdliner_term base_state ? default_interactivity ? ...
module Entry = struct type t = { name_length : int ; doc_length : int ; aliases : string list } let create ( ? aliases = [ ] ) name_length doc_length = { name_length ; doc_length ; aliases } ; ; let generate_string ~ spaces length = List . init length ~ f ( : fun x -> if x % 10 = 0 && spaces then ' ' else ' a ' ) |> St...
let display entries = List . mapi entries ~ f ( : fun idx entry -> Entry . to_flag_info entry ~ idx ) |> Flag_info . to_string |> print_endline ; ; display [ Entry . create 7 10 ; Entry . create 17 100 ~ aliases [ : " hi " ] ; Entry . create 27 30 ; Entry . create 37 40 ] ; [ % expect { | aaaaaaaaa aaaaaaaaa aaaaaaaaa ...
let mode lang = Funcall . Wrap . ( lang ^ " - mode " <: nullary @-> return nil ) ( ) Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> mode " c " ; let show var sexp_of_a = print_s [ % sexp ( var ( ) : a ) ] in show start String . sexp_of_t ; [ % expect { | " /* " } ] ; | show end_ String . sexp_of_t ; ...
let test ? position ( ) = let position = Option . value_map position ~ f : Position . of_int_exn ~ default ( : Point . get ( ) ) in let one_fn name f = print_endline [ % string " { % name } " ] ; : Point . goto_char position ; Ecaml_test_helpers . show ( ) ; print_endline " " ; => match f ( ) with | ( ) -> Ecaml_test_h...
type debug_level = | Debug_only | User_info ; ;
let log = fun level -> let k m = match debug , level with | User_info , Debug_only -> ( ) | _ , _ -> Printf . printf " % s \ n " %! m in Printf . kprintf k ; ;
let sleep_float n = let _ = Unix . select [ ] [ ] [ ] n in ( ) ; ;
let print_timings start_space start_wtime start_ptime = let end_ptime = Unix . times ( ) in let self_u = end_ptime . Unix . tms_utime . - start_ptime . Unix . tms_utime in let self_s = end_ptime . Unix . tms_stime . - start_ptime . Unix . tms_stime in let self = self_u . + self_s in let child_u = end_ptime . Unix . tms...
let run func args = Gc . compact ( ) ; let start_space = Gc . quick_stat ( ) in let start_wtime = Unix . time ( ) in let start_ptime = Unix . times ( ) in let ret = try func args with e -> print_timings start_space start_wtime start_ptime ; raise e in print_timings start_space start_wtime start_ptime ; ret ; ;
let string_list_eq l1 l2 = List . fold_left2 ( fun eq x1 x2 -> if eq = false then false else if Bytes . compare x1 x2 = 0 then true else false ) true l1 l2 ; ;
let allocate ( ? random = true ) how_many str_len = let l = ref [ ] in for _i = 1 to how_many do let s = Bytes . create str_len in for j = 0 to ( str_len - 1 ) do if random then Bytes . set s j ( Char . chr ( Random . int 256 ) ) else Bytes . set s j ' x ' done ; l := s ( ::! l ) ; done ; ! l ; ;
let allocate_a_lot ( ) = allocate 47 9973 ; ;
let allocate_many_small ( ) = allocate 9973 47 ; ;
let rec run_tests con = function | 0 -> return ( ) | n -> let message = Gen_random . message ( ) in let % lwt ( ) = OBus_connection . send_message con { message with destination = name ; typ = Signal ( [ " obus " ; " test " ] , " obus . test " , " test " ) ; } in run_tests con ( n - 1 )
let rec wait_for_name con = OBus_bus . name_has_owner con name >>= function | true -> return ( ) | false -> let % lwt ( ) = Lwt_unix . sleep 0 . 1 in wait_for_name con
let test ( ) = let % lwt ( ) = Lwt_io . flush Lwt_io . stdout in match Unix . fork ( ) with | 0 -> let % lwt con = OBus_bus . session ( ) in let % lwt ( ) = wait_for_name con in let % lwt ( ) = run_tests con test_count in exit 0 | pid -> let % lwt ( ) = printlf " sending and receiving % d messages through the message b...
module type S = sig type t [ @@ deriving sexp_of ] include Comparable . Polymorphic_compare with type t := t end
let test ( type a ) here ( module T : S with type t = a ) list = let op ( type b ) ( module Result : S with type t = b ) operator ~ actual ~ expect = With_return . with_return ( fun failed -> List . iter list ~ f ( : fun arg1 -> List . iter list ~ f ( : fun arg2 -> let actual = actual arg1 arg2 in let expect = expect a...
let assoc_compare l1 l2 = if List . length l1 <> List . length l2 then false else List . fold_left ( fun acc ( k , v ) -> acc && List . assoc k l2 = v ) true l1
let unordered_list_compare l1 l2 = if List . length l1 <> List . length l2 then false else List . fold_left ( fun acc x -> acc && List . mem x l2 ) true l1
let filedict_equal d1 d2 = assert_equal ~ cmp : assoc_compare ( FileDict . to_list d1 ) ( FileDict . to_list d2 )
let compdict_equal d1 d2 = assert_equal ~ cmp : assoc_compare ( CompDict . to_list d1 ) ( CompDict . to_list d2 )
let se_dict = FileDict . insert " a " [ ( 1 , 0 ) ] emp_file
let de_dict = FileDict . ( empty |> insert " a " [ ( 1 , 0 ) ; ( 2 , 0 ) ] |> insert " b " [ ( 1 , 0 ) ; ( 3 , 0 ) ] )
let emp_e_dict = FileDict . ( empty |> insert " a " [ ] |> insert " b " [ ( 7 , 0 ) ; ( 4 , 0 ) ] |> insert " c " [ ( 4 , 0 ) ; ( 8 , 0 ) ; ( 13 , 0 ) ] )
let def_p_comp = FileDict . ( empty |> insert " a " [ ( 1 , 0 ) ; ( 2 , 0 ) ] |> insert " b " [ ( 1 , 0 ) ] )
let des_p_comp = FileDict . ( empty |> insert " a " [ ( 1 , 0 ) ] |> insert " b " [ ( 1 , 0 ) ; ( 3 , 0 ) ] )
let emp_e_f_p_comp = FileDict . ( empty |> insert " a " [ ] |> insert " b " [ ] |> insert " c " [ ] )
let emp_e_s_p_comp = FileDict . ( empty |> insert " a " [ ] |> insert " b " [ ( 7 , 0 ) ; ( 4 , 0 ) ] |> insert " c " [ ( 4 , 0 ) ] )
let emp_e_t_p_comp = FileDict . ( empty |> insert " a " [ ] |> insert " b " [ ( 4 , 0 ) ] |> insert " c " [ ( 4 , 0 ) ; ( 8 , 0 ) ; ( 13 , 0 ) ] )
let se_comp = CompDict . ( insert " a " se_dict empty )
let def_comp = CompDict . ( insert " a " def_p_comp empty )
let de_comp = CompDict . insert " b " des_p_comp def_comp
let emp_e_comp = CompDict . ( empty |> insert " a " emp_e_f_p_comp |> insert " b " emp_e_s_p_comp |> insert " c " emp_e_t_p_comp )
let get_files = List . map ( fun ( k , s ) -> k )
let tests = [ " empty lists " >:: ( fun _ -> assert_equal ~ cmp : assoc_compare [ ] ( intersection [ ] [ ] ) ) ; " one list empty " >:: ( fun _ -> assert_equal ~ cmp : assoc_compare [ ] ( ( intersection [ ( 12 , 7 ) ; ( 9 , 13 ) ] [ ] ) ) ) ; " single lists uneq " >:: ( fun _ -> assert_equal ~ cmp : assoc_compare [ ] (...
module M = Interp . Monad ( struct let trace = false end ) ( Interp . State_poly )
module O = Interp . Opcodes ( M )
module Sim = Cyclesim . With_interface ( Sequential . I ) ( Sequential . O )
let simulate_instruction instr = let _ , instr = O . dispatch instr Interp . State_poly . empty in let sim = Sim . create ~ is_internal_port ( : Fn . const true ) ( Sequential . compile instr ) in let i : _ Sequential . I . t = Cyclesim . inputs sim in let waves , sim = Waveform . create sim in let set x i = x := Bits ...
let collection = Collection . This [ " foo " ; " bar " ; " baz " ]
let prompt = " " let % bind ( ) = with_input_macro " bar TAB RET " ( fun ( ) -> let % bind response = read ~ prompt ~ collection ~ history : Minibuffer . history ( ) in print_s [ % sexp ( response : string ) ] ; return ( ) ) in [ % expect { | bar } ] ; | return ( ) ; ; let % bind ( ) = with_input_macro " f TAB RET " ( ...
let testlib = Dl . ( dlopen ~ filename " : clib / libtest_functions . so " ~ flags [ : RTLD_NOW ] )
module Common_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module M = Functions . Common ( S ) open M let test_complex_primitive_operations _ = let wrap ' typ1 typ2 f l r = let rv = allocate_n ~ count : 1 typ2 in f ( allocate typ1 l ) ( allocate typ2 r ) rv ; !@ rv in let...
module Build_stub_tests ( S : Cstubs . FOREIGN with type ' a result = ' a and type ' a return = ' a ) = struct module N = Functions . Stubs ( S ) open N include Common_tests ( S ) let test_complex_primitive_value_operations _ = begin let open Complex in let eps64 = 1e - 12 in let complex64_eq { re = lre ; im = lim } { ...
let suite = " Complex number tests " >::: [ " basic operations on complex numbers ( foreign ) " >:: Foreign_tests . test_complex_primitive_operations ; " basic operations on complex numbers ( stubs ) " >:: Stub_tests . test_complex_primitive_operations ; " basic operations on complex numbers passed by value ( stubs ) "...
let _ = run_test_tt_main suite
let e_by_taylor_series ( ) = let rec aux s t i = if Doubledouble . to_float t > Doubledouble . k_eps then let t = t . . / Doubledouble . of_int i in aux ( s . . + t ) t ( succ i ) else s in Doubledouble . ( aux ( of_int 2 ) ( of_int 1 ) 2 )
let arctan_by_taylor_series x = let x2 = Doubledouble . sqr x in let rec aux ~ t ~ at ~ d ~ sign = let at = if sign then at . . + Doubledouble . ( pow x d . . / of_int d ) else at . . - Doubledouble . ( pow x d . . / of_int d ) in if Doubledouble . to_float t > Doubledouble . k_eps then aux ~ t ( : t . . * x2 ) ~ at ~ ...
let pi_by_machin ( ) = let t1 = Doubledouble . ( one . . / of_int 5 ) in let t2 = Doubledouble . ( one . . / of_int 239 ) in let d4 = Doubledouble . of_int 4 in let pi4 = d4 . . * arctan_by_taylor_series t1 . . - arctan_by_taylor_series t2 in pi4 . . * d4
let ( ) = let e = e_by_taylor_series ( ) in let err = abs_float ( Doubledouble . to_float ( e . . - Doubledouble . e ) ) in assert ( err < 64 . . * Doubledouble . k_eps )
let ( ) = let pi = pi_by_machin ( ) in let err = abs_float ( Doubledouble . to_float ( pi . . - Doubledouble . pi ) ) in prerr_endline ( Doubledouble . to_string pi ) ; prerr_endline Doubledouble . ( to_string pi ) ; Printf . eprintf " . % 37f \ n " %! err ; assert ( err < 8 . . * Doubledouble . k_eps )
module Container_images = struct type t = { mina : string ; archive_node : string ; user_agent : string ; bots : string ; points : string } end
module Wallet = struct type t = { balance : string ; timing : Mina_base . Account_timing . t } end
type constants = { constraints : Genesis_constants . Constraint_constants . t ; genesis : Genesis_constants . t }
type t = { requires_graphql : bool ; k : int ; delta : int ; slots_per_epoch : int ; slots_per_sub_window : int ; txpool_max_size : int ; block_producers : Wallet . t list ; extra_genesis_accounts : Wallet . t list ; num_snark_workers : int ; num_archive_nodes : int ; log_precomputed_blocks : bool ; snark_worker_fee : ...
let proof_config_default : Runtime_config . Proof_keys . t = { level = Some Full ; sub_windows_per_window = None ; ledger_depth = None ; work_delay = None ; block_window_duration_ms = Some 120000 ; transaction_capacity = None ; coinbase_amount = None ; supercharged_coinbase_factor = None ; account_creation_fee = None ;...
let default = { requires_graphql = false ; k = 20 ; slots_per_epoch = 3 * 8 * 20 ; slots_per_sub_window = 2 ; delta = 0 ; txpool_max_size = 3000 ; block_producers = [ ] ; extra_genesis_accounts = [ ] ; num_snark_workers = 0 ; num_archive_nodes = 0 ; log_precomputed_blocks = false ; snark_worker_fee = " 0 . 025 " ; snar...
let simple_open_default ( ) = Utils . with_tmp_dir begin fun name -> open_db ~ config : Options . default ~ name >>= fun _ -> Ok ( ) end
let open_not_random_setters ( ) = Utils . with_tmp_dir begin fun name -> let block_cache = Options . Cache . LRU . create ~ size ( : 10 * 1024 * 1024 ) in let filter_policy = Options . Filter_policy . create_bloom_full ~ bits_per_key : 12 in let block_based_table = Options . Tables . Block_based . create ~ block_size (...
let open_error ( ) = Utils . with_tmp_dir begin fun name -> let config = { Options . default with create_if_missing = false } in match open_db ~ config ~ name with | Error _ -> Ok ( ) | Ok _ -> Error ( ` Msg " Test_config_and_open . open error failed : open was successful " ) end
let tests = [ " simple_open_default " , simple_open_default ; " open_not_random_setters " , open_not_random_setters ; " open_error " , open_error ; ]
let advance_by_span time_source span = let to_ = Time_ns . add ( Synchronous_time_source . now time_source ) span in Synchronous_time_source . advance_by_alarms time_source ~ to_ |> ok_exn ; ;
let heartbeat_every = sec 2 .
let heartbeat_timeout = sec 10 .
let yield ( ) = Async_kernel_scheduler . yield_until_no_jobs_remain ( )
let establish_connection transport time_source description = let conn = Connection . create ~ connection_state ( : fun _ -> ( ) ) ~ heartbeat_config : ( Connection . Heartbeat_config . create ~ timeout : heartbeat_timeout ~ send_every : heartbeat_every ( ) ) ~ description ~ time_source transport in Deferred . upon conn...
let int32_of_timestamp ts = let i64 = Timestamp . to_seconds ts in let i32 = Int64 . to_int32 i64 in if Int64 . ( equal ( of_int32 i32 ) i64 ) then Ok i32 else Environment . Error_monad . error Generation_failure
let int32_of_timestamp_exn ts = match int32_of_timestamp ts with | Ok i32 -> i32 | Error _err -> Stdlib . failwith " int32_of_timestamp_exn : number too big "
let timestamp_of_int32 ts = Timestamp . of_seconds ( Int64 . of_int32 ts )
module Generator = struct open QCheck2 . Gen let decorate ( ? prefix = " " ) ( ? suffix = " " ) printer d = prefix ^ printer d ^ suffix let config = let + x = opt small_nat in config x let print_config = decorate ~ prefix " : clock_drift " ( fun config -> Option . fold ~ none " : round_0 duration " ~ some ( : fun drift...
let assert_no_error d = match d with Error _ -> assert false | Ok d -> d
let round_durations : Round . round_durations = assert_no_error @@ Round . Durations . create ~ first_round_duration : Period . ( of_seconds_exn 4L ) ~ delay_increment_per_round : Period . ( of_seconds_exn 10L )
let round_zero_duration = Round . round_duration round_durations Round . zero
let no_error = function | Ok b -> b | Error errs -> Format . printf " test fail due to error : % a . " @ Error_monad . pp_print_trace ( Environment . wrap_tztrace errs ) ; false
let durations round_durations start stop = List . map_e ( fun round -> Round . of_int round >|? fun round -> Round . round_duration round_durations round |> Period . to_seconds ) Tezos_stdlib . Utils . Infix . ( start -- stop )
let timestamp_of_round round_durations ~ proposal_timestamp ~ proposal_round ~ round = ( let iproposal_round = Int32 . to_int @@ Round . to_int32 proposal_round in let iround = Int32 . to_int @@ Round . to_int32 round in if Round . ( proposal_round = round ) then ok ( Period . zero , proposal_timestamp ) else if Round ...
let drift_of = let r0_dur = Round . round_duration round_durations Round . zero in fun clock_drift -> Option . value ~ default : r0_dur clock_drift
let max_ts clock_drift prop_ts now = Timestamp . ( max prop_ts now +? drift_of clock_drift )
let predecessor_start proposal_timestamp proposal_round grandparent_round = assert_no_error @@ ( Round . level_offset_of_round round_durations ~ round : Round . ( succ grandparent_round ) >>? fun proposal_level_offset -> Round . level_offset_of_round round_durations ~ round : proposal_round >>? fun proposal_round_offse...
let test_acceptable_past_level = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : acceptable past op " ( Generator . param_acceptable ( ) ) ( fun ( config , ( ( ( proposal_round , op_round ) , ( proposal_level , op_level ) ) , ( proposal_timestamp , now_timestamp ) ) ) -> Raw_leve...
let test_acceptable_current_level_current_round = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : same round , same level " Generator . ( param_acceptable ~ rounds : same_rounds ~ levels : same_levels ( ) ) ( fun ( config , ( ( ( op_round , _ ) , ( _ , op_level ) ) , ( proposal_t...
let test_acceptable_current_level = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : same level , different round , acceptable op " Generator . ( param_acceptable ~ levels : same_levels ( ) ) ( fun ( config , ( ( ( proposal_round , op_round ) , ( _ , op_level ) ) , ( proposal_time...
let test_not_acceptable_current_level = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : same level , different round , too far " Generator . ( param_acceptable ~ levels : same_levels ( ) ) ( fun ( config , ( ( ( proposal_round , op_round ) , ( _ , op_level ) ) , ( proposal_timest...
let test_acceptable_next_level = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : next level , acceptable op " Generator . ( param_acceptable ~ levels : same_levels ( ) ) ( fun ( config , ( ( ( proposal_round , op_round ) , ( proposal_level , _ ) ) , ( proposal_timestamp , now_tim...
let test_not_acceptable_next_level = let open QCheck2 in Test . make ~ print : Generator . print_param_acceptable ~ name " : next level , too far " Generator . ( param_acceptable ~ levels : same_levels ~ timestamps : successive_timestamp ( ) ) ( fun ( config , ( ( ( proposal_round , op_round ) , ( proposal_level , _ ) ...
let ( ) = Alcotest . run " Filter " [ ( " pre_filter " , qcheck_wrap [ test_acceptable_past_level ; test_acceptable_current_level_current_round ; test_acceptable_current_level ; test_not_acceptable_current_level ; test_acceptable_next_level ; test_not_acceptable_next_level ; ] ) ; ]
let prn = function | Consensus hash -> Format . asprintf " Consensus with % a " Block_hash . pp hash | No_consensus _ -> " No consensus " | Need_more_candidates -> " Synchronised ( not stuck ) "
let forge_peer_id ( ) = let identity = P2p_identity . generate_with_pow_target_0 ( ) in identity . peer_id
let forge_hash ( ) = Block_hash . hash_bytes [ Bytes . init 32 ( fun _ -> Char . chr ( Random . int 256 ) ) ]
let create_state_init_1 ( ) = let h = create ~ expected : 1 ~ threshold : 1 ( ) in Assert . equal ( get_state h ) Need_more_candidates