text stringlengths 12 786k |
|---|
let wrap e = Lwt . return ( Environment . wrap_tzresult e ) |
let iter_n_es n f = let rec aux k = if k = n then return ( ) else f k >>=? fun ( ) -> aux ( k + 1 ) in aux 0 |
module Samplers = struct let size = { Tezos_benchmark . Base_samplers . min = 4 ; max = 32 } module Crypto_samplers = Tezos_benchmark . Crypto_samplers . Make_finite_key_pool ( struct let size = 10 let algo = ` Default end ) include Michelson_samplers . Make ( struct let parameters : ... |
module Printers = struct let string_of_something f = Lwt_main . run ( let accounts = Account . generate_accounts 1 in Block . alpha_context accounts >>=? fun ctxt -> f ctxt >>= wrap >>=? fun node -> let printable = Micheline_printer . printable Protocol . Michelson_v1_primitives . string_of_prim... |
module Tests = struct let footprint v = 8 * Obj . ( reachable_words ( repr v ) ) let stats = Stdlib . Hashtbl . create 13 let remember what vsize rsize = Stdlib . Hashtbl . add stats what ( vsize , rsize ) let check_good_approximation kind ratio what vsize x = let rsize = footprint x in... |
let tests = let open Tztest in Tests . [ tztest " lambda size is a good approximation ( fast ) " ` Quick ( fun ( ) -> lambda_size 50 ) ; tztest " ty size is a good approximation ( fast ) " ` Quick ( fun ( ) -> ty_size 50 ) ; tztest " value size is a good approximation ... |
let err x = Exn ( Sc_rollup_test_error x ) |
let test_disable_feature_flag ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in Incremental . begin_construction b >>=? fun i -> let kind = Sc_rollup . Kind . Example_arith in let boot_secto... |
let test_sc_rollups_all_well_defined ( ) = let all_contains_all_constructors ( ) = let tickets = ref [ " Example_arith " ] in let burn x = tickets := List . filter ( ( <> ) x ) ! tickets in let pick = function | Sc_rollup . Kind . Example_arith -> burn " Example_arith " in Li... |
let tests = [ Tztest . tztest " check effect of disabled feature flag " ` Quick test_disable_feature_flag ; Tztest . tztest " check that all rollup kinds are correctly enumerated " ` Quick test_sc_rollups_all_well_defined ; ] |
let add_byte b = Bytes . concat ( Bytes . of_string ) " " [ b ; Bytes . of_string " \ x00 ] " |
let test_equal_keys ctxt = let sk = Bytes . of_string ( String . make ( Secret_box . key_size ) key_size ' A ' ) ' A ' in let sk ' = Bytes . of_string ( " B " ^ ( String . make ( Secret_box . key_size - 1 ) 1 ' A ' ) ' A ' ) ' A ' in let sk ' ' = Bytes . of_string... |
let test_permute ctxt = let k = Secret_box . random_key ( ) in assert_raises ( Size_mismatch " Secret_box . to_key ) " ( fun ( ) -> ( Secret_box . Bytes . to_key ( add_byte ( Secret_box . Bytes . of_key k ) k ) k ) k ) k |
let test_nonce_operations ctxt = let n = Bytes . of_string ( String . make Secret_box . nonce_size ' \ x00 ' ) x00 ' in let n ' = Bytes . of_string ( ( String . make ( Secret_box . nonce_size - 1 ) 1 ' \ x00 ' ) x00 ' ^ " \ x01 ) " in let n ' ' = Bytes . of_string ... |
let setup ( ) = Secret_box . random_key ( ) , Bytes . of_string " wild wild fox " , Secret_box . random_nonce ( ) |
let test_secret_box ctxt = let k , msg , nonce = setup ( ) in let cmsg = Secret_box . Bytes . secret_box k msg nonce in let msg ' = Secret_box . Bytes . secret_box_open k cmsg nonce in assert_equal msg msg ' |
let test_secret_box_fail_permute ctxt = let k , msg , nonce = setup ( ) in let cmsg = Secret_box . Bytes . secret_box k msg nonce in Bytes . set cmsg 10 ' a ' ; assert_raises Verification_failure ( fun ( ) -> ignore ( Secret_box . Bytes . secret_box_open k cmsg nonce ) nonce ) nonce |
let test_secret_box_fail_key ctxt = let k , msg , nonce = setup ( ) in let k ' = Secret_box . random_key ( ) in let cmsg = Secret_box . Bytes . secret_box k msg nonce in assert_raises Verification_failure ( fun ( ) -> ignore ( Secret_box . Bytes . secret_box_open k ' cmsg nonce ) no... |
let suite = " Secret_box " >::: [ " test_equal_keys " >:: test_equal_keys ; " test_nonce_operations " >:: test_nonce_operations ; " test_permute " >:: test_permute ; " test_secret_box " >:: test_secret_box ; " test_secret_box_fail_permute " >:: test_secret_box_fail_permute ; "... |
let test_no_commitment ( ) = Context . init ~ consensus_threshold : 0 5 >>=? fun ( b , _ ) -> Context . get_constants ( B b ) >>=? fun { parametric = { blocks_per_commitment ; _ } ; _ } -> let blocks_per_commitment = Int32 . to_int blocks_per_commitment in Block . bake_n ... |
let test_revelation_early_wrong_right_twice ( ) = let open Assert in Context . init ~ consensus_threshold : 0 5 >>=? fun ( b , _ ) -> Context . get_constants ( B b ) >>=? fun csts -> let tip = csts . parametric . seed_nonce_revelation_tip in let blocks_per_commitment = Int32 . to_int... |
let test_revelation_missing_and_late ( ) = let open Context in let open Assert in Context . init ~ consensus_threshold : 0 5 >>=? fun ( b , _ ) -> get_constants ( B b ) >>=? fun csts -> let blocks_per_commitment = Int32 . to_int csts . parametric . blocks_per_commitment in Block . bak... |
let wrap e = e >|= Environment . wrap_tzresult |
let test_unrevealed ( ) = let open Alpha_context in let constants = { Default_parameters . constants_test with endorsing_reward_per_slot = Tez . one_mutez ; baking_reward_bonus_per_slot = Tez . zero ; baking_reward_fixed_portion = Tez . zero ; seed_nonce_revelation_tip = Tez . zero ; conse... |
let tests = [ Tztest . tztest " no commitment " ` Quick test_no_commitment ; Tztest . tztest " revelation_early_wrong_right_twice " ` Quick test_revelation_early_wrong_right_twice ; Tztest . tztest " revelation_missing_and_late " ` Quick test_revelation_missing_and_late ; Tztest . tzt... |
let show_all ( ) = print_s [ % sexp ( Frame . window_list ( ) : Window . t list ) ] |
let show ( ) = print_s [ % sexp ( get ( ) : Window . t ) ] show ( ) ; [ % expect { | " #< window 1 on * scratch " *> } ] ; | return ( ) ; ; Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Blocking . switch_to_buffer ( Current_buffer ... |
let window1 , window4 = match Frame . window_list ( ) with | [ x ; y ] -> x , y | [ w ] -> w , w | _ -> raise_s [ % message [ % here ] ] ; ; show ( ) ; [ % expect { | " #< window 1 on * scratch " *> } ] ; | set window4 ; show ( ) ; [ % ex... |
let valids , invalids , sorted = let json = Yojson . Basic . from_file " fixtures . json " in let open Yojson . Basic . Util in let read_list key = json |> member key |> to_list |> List . map to_string in read_list " valid " , read_list " invalid " , read_list " compare " |
let test_valids ( ) = let assert_iso v = match of_string v with | Some v ' -> assert_equal ( to_string v ' ) v ; assert_equal ( Format . asprintf " % a " Semver . pp v ' ) v | None -> assert_failure ( " valid version detected as invalid : " ^ v ) in List . iter assert_iso ... |
let test_invalids ( ) = List . iter ( fun v -> assert_bool ( v ^ " is invalid " ) ( not ( is_valid v ) ) ) invalids |
let test_compare ( ) = let rec of_string_list parsed raw = match raw with | [ ] -> parsed | hd :: tl -> match of_string hd with | Some v -> of_string_list ( v :: parsed ) tl | None -> of_string_list parsed tl in let list_printer lst = " \ n [ \ n " ^ ( lst |> List . map ( fun s ... |
let test_from_parts ( ) = let is_success = function | None -> false | Some _ -> true in assert_bool " negative version rejected " ( not ( is_success ( from_parts ( - 1 ) 0 2 [ ] [ ] ) ) ) ; assert_bool " invalid prerelease rejected " ( not ( is_success ( from_parts... |
let suite = " semver suite " >::: [ " test valids " >:: test_valids ; " test invalids " >:: test_invalids ; " test compare " >:: test_compare ; " test from_parts " >:: test_from_parts ] |
let _ = run_test_tt_main suite |
let romain_calascibetta = let open Mrmime in let open Mailbox in Local . [ w " romain " ; w " calascibetta " ] @ Domain . ( domain , [ a " gmail " ; a " com " ] ) |
let anil = let open Mrmime in let open Mailbox in Local . [ w " anil " ] @ Domain . ( domain , [ a " recoil " ; a " org " ] ) |
module Unix_scheduler = Colombe . Sigs . Make ( struct type ' a t = ' a end ) |
let unix = { Colombe . Sigs . bind = ( fun x f -> let open Unix_scheduler in f ( prj x ) ) ; return = ( fun x -> Unix_scheduler . inj x ) ; } |
let put_crlf x = x ^ " \ r \ n " |
let rdwr_from_flows inputs outputs = let inputs = ref ( List . map put_crlf inputs ) in let outputs = ref ( List . map put_crlf outputs ) in let read ( ) bytes off len = match ! inputs with | [ ] -> Unix_scheduler . inj ` End | x :: r -> let len = min ( String . length x ) len i... |
let test_0 ( ) = Alcotest . test_case " usual without authentication " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your serv... |
let test_1 ( ) = Alcotest . test_case " usual with authentication " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your service... |
let test_2 ( ) = Alcotest . test_case " bad authentication " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESMTP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ ... |
let test_3 ( ) = Alcotest . test_case " PLAIN mechanism unavailable " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESMTP - gsmtp " ; " 250 - smtp . gmail . com at your servi... |
let test_4 ( ) = Alcotest . test_case " authentication required " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , _is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESMTP - gsmtp " ; " 250 - smtp . gmail . com at your service... |
let test_5 ( ) = Alcotest . test_case " 8BITMIME " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ 8 . ... |
let test_6 ( ) = Alcotest . test_case " spam " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ 8 . 8 . ... |
let test_7 ( ) = Alcotest . test_case " ethereal " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ 8 . 8... |
let stream_of_string str = let once = ref false in fun ( ) -> if ! once then None else ( once := true ; Some ( str , 0 , String . length str ) ) |
let stream_of_strings vs = let vs = ref vs in fun ( ) -> match ! vs with | [ ] -> None | hd :: tl -> vs := tl ; Some ( hd , 0 , String . length hd ) |
let _78_a_with_dot_rw = [ String . make 78 ' a ' ^ " \ r \ n " ; " . " ^ String . make 77 ' a ' ] |
let _75_a_with_dot_qp = String . make 75 ' a ' ^ " . " ^ String . make 74 ' a ' |
let test_8 ( ) = Alcotest . test_case " dot " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let mail = let open Mrmime in let subject = Unstructured . Craft . ( compile [ v " Simple " ; sp 1 ; v " Mail " ] ) in let hd0 = let content0 =... |
let test_9 ( ) = Alcotest . test_case " base64 " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESTMP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ 8 . 8 ... |
let test_10 ( ) = Alcotest . test_case " unproperly quit " ` Quick @@ fun ( ) -> let ctx = Colombe . State . Context . make ( ) in let rdwr , is_empty = rdwr_from_flows [ " 220 smtp . gmail . com ESMTP - gsmtp " ; " 250 - smtp . gmail . com at your service , [ ... |
let ( ) = Alcotest . run " sendmail " [ ( " mock " , [ test_0 ( ) ; test_1 ( ) ; test_2 ( ) ; test_3 ( ) ; test_4 ( ) ; test_5 ( ) ; test_6 ( ) ; test_7 ( ) ; test_8 ( ) ; test_9 ( ) ; test_10 ( ) ; ] ) ; ] |
module String_sequence = GLib . Sequence . Make ( struct type t = char let t_typ = char end ) |
let test_empty_sequence test_ctxt = let s = String_sequence . create ( fun _ -> ( ) ) in let len = String_sequence . length s in let ( ) = assert_equal_uint ( Unsigned . UInt . zero ) len in let is_empty = String_sequence . is_empty s in assert_equal_boolean true is_empty |
let tests = " GLib2 sequence module tests " >::: [ " Test empty sequence " >:: test_empty_sequence ; ] |
let ( >>== ) p v = Lwt_main . run ( Lwt . map ( ( = ) v ) p ) |
let ( ) = let open Support . Lib . Seq in assert ( first empty = None ) ; assert ( first ( return 0 ) = Some 0 ) ; assert ( first ( cons 0 empty ) = Some 0 ) ; assert ( first ( append empty empty ) = None ) ; assert ( List . of_seq empty = [ ] ) ; assert... |
let ( ) = let open Support . Lib . Seq_e in assert ( first empty = None ) ; assert ( first ( return 0 ) = Some ( Ok 0 ) ) ; assert ( first ( return_e ( Ok 0 ) ) = Some ( Ok 0 ) ) ; assert ( first ( return_e ( Error ( ) ) ) = Some ( Error ( ) ) ... |
let ( ) = let open Support . Lib . Seq_s in assert ( first empty >>== None ) ; assert ( first ( return 0 ) >>== Some 0 ) ; assert ( first ( cons 0 empty ) >>== Some 0 ) ; assert ( first ( append empty empty ) >>== None ) |
let ( ) = let open Support . Lib . Seq_es in assert ( first empty >>== None ) ; assert ( first ( return 0 ) >>== Some ( Ok 0 ) ) ; assert ( first ( return_e ( Ok 0 ) ) >>== Some ( Ok 0 ) ) ; assert ( first ( return_e ( Error ( ) ) ) >>== Some ( Erro... |
type result = { success : int ; failure : int ; reading_error : int ; writing_error : int ; } |
let run_one_test byte_order msg acc = try let str , fds = OBus_wire . string_of_message ~ byte_order msg in let msg ' = OBus_wire . message_of_string str fds in if msg ' = msg then { acc with success = acc . success + 1 } else begin { acc with failure = acc . failure + 1 } end with | O... |
let run_tests prefix byte_order l = let % lwt progress = Progress . make prefix test_count in let rec aux acc n = function | [ ] -> let % lwt ( ) = Progress . close progress in return acc | msg :: l -> let % lwt ( ) = Progress . incr progress in aux ( run_one_test byte_order msg acc ) ... |
let print_result result = let % lwt ( ) = printf " success : % d \ n " result . success in let % lwt ( ) = printf " failure : % d \ n " result . failure in let % lwt ( ) = printf " writing error : % d \ n " result . writing_error in let % lwt ( ) = printf " reading ... |
let rec gen_messages progress acc = function | 0 -> let % lwt ( ) = Progress . close progress in return acc | n -> let % lwt ( ) = Progress . incr progress in gen_messages progress ( Gen_random . message ( ) :: acc ) ( n - 1 ) |
let test ( ) = let % lwt progress = Progress . make ( Printf . sprintf " generating % d messages " test_count ) test_count in let % lwt msgs = gen_messages progress [ ] test_count in let % lwt ( ) = printl " try to serialize / deserialize all messages and compare the result to the ori... |
let serve_tls port handler = let % bind certificate = Tls_async . X509_async . Certificate . of_pem_file server_cert |> Deferred . Or_error . ok_exn in let % bind priv_key = Tls_async . X509_async . Private_key . of_pem_file server_key |> Deferred . Or_error . ok_exn in let config = Tls . ... |
let test_server port = let handler ( _ : Socket . Address . Inet . t ) ( _ : Tls_async . Session . t ) rd wr = let pipe = Reader . pipe rd in let rec read_from_pipe ( ) = ( match % map Pipe . read pipe with | ` Ok line -> Writer . write wr line | ` Eof -> ( ) ) >>= ... |
let cmd = let open Command . Let_syntax in Command . async ~ summary " : test server " ( let % map_open port = anon ( " PORT " %: int ) in fun ( ) -> let open Deferred . Let_syntax in let % bind server = test_server port in Tcp . Server . close_finished server ) ; ; |
let ( ) = Command_unix . run cmd |
let trace fmt = Format . ksprintf ( Format . printf " % s \ n ) " %! fmt |
let request_error_pp_hum fmt = function | ` Bad_request -> Format . fprintf fmt " Bad_request " | ` Bad_gateway -> Format . fprintf fmt " Bad_gateway " | ` Internal_server_error -> Format . fprintf fmt " Internal_server_error " | ` Exn exn -> Format . fprintf fmt " Exn ( % s ) s ... |
module Alcotest = struct include Alcotest let request_error = Alcotest . of_pp request_error_pp_hum let request = Alcotest . of_pp ( fun fmt req -> Format . fprintf fmt " % s " ( request_to_string req ) req ) req ; ; end |
module Runtime : sig type t val create : ? config : Config . t -> ? error_handler : Server_connection . error_handler -> Server_connection . request_handler -> t val current_read_operation : t -> Read_operation . t val current_write_operation : t -> Write_operation . t val do_read : t -> ( Serve... |
let read ( ? eof = false ) false t str ~ off ~ len = do_read t ( fun conn -> if eof then Server_connection . read_eof conn str ~ off ~ len else Server_connection . read conn str ~ off ~ len ) len ; ; |
let read_eof = read ~ eof : true |
let feed_string ? eof t str = let len = String . length str in let input = Bigstringaf . of_string str ~ off : 0 ~ len in read ? eof t input ~ off : 0 ~ len ; ; |
let read_string ? eof t str = let c = feed_string ? eof t str in Alcotest ( . check int ) int " read consumes all input " ( String . length str ) str c ; ; ; |
let read_request ? eof t r = let request_string = request_to_string r in read_string ? eof t request_string ; ; |
let reader_ready t = Alcotest . check read_operation " Reader is ready " ` Read ( current_read_operation t ) t ; ; ; |
let reader_yielded t = Alcotest . check read_operation " Reader is in a yield state " ` Yield ( current_read_operation t ) t ; ; ; |
let reader_closed t = Alcotest . check read_operation " Reader is closed " ` Close ( current_read_operation t ) t ; ; ; |
let write_partial_string ( ? msg " = output written ) " t expected len = do_write t ( fun conn bufs -> let actual = String . sub ( Write_operation . iovecs_to_string bufs ) bufs 0 len in Alcotest ( . check string ) string msg ( String . sub expected 0 len ) len actual ; Server_connec... |
let write_string ( ? msg " = output written ) " t expected = do_write t ( fun conn bufs -> let len = String . length expected in let actual = Write_operation . iovecs_to_string bufs in Alcotest ( . check string ) string msg expected actual ; Server_connection . report_write_result conn ( ` ... |
let write_response ( ? msg " = response written ) " ? body t r = let response_string = response_to_string ? body r in write_string ~ msg t response_string ; ; |
let write_eof t = do_write t ( fun conn _ -> Server_connection . report_write_result conn ` Closed ) Closed ; ; |
let writer_ready t = let is_write = Alcotest . testable Write_operation . pp_hum ( fun a b -> match a , b with | ` Write _ , ` Write _ -> true | _ -> false ) false in Alcotest . check is_write " Writer is ready " ( ` Write [ ] ) ( current_write_operation t ) t ; ; ; |
let writer_yielded t = Alcotest . check write_operation " Writer is in a yield state " ` Yield ( current_write_operation t ) t ; ; ; |
let writer_closed ( ? unread = 0 ) 0 t = Alcotest . check write_operation " Writer is closed " ( ` Close unread ) unread ( current_write_operation t ) t ; ; ; |
let connection_is_shutdown t = reader_closed t ; writer_closed t ; ; ; |
let raises_writer_closed f = Alcotest . check_raises " raises because writer is closed " ( Failure " cannot write to closed writer ) " f ; ; |
let request_handler_with_body body reqd = Body . Reader . close ( Reqd . request_body reqd ) reqd ; Reqd . respond_with_string reqd ( Response . create ` OK ) OK body ; ; |
let default_request_handler reqd = request_handler_with_body " " reqd ; ; |
let echo_handler response reqd = let request_body = Reqd . request_body reqd in let response_body = Reqd . respond_with_streaming reqd response in let rec on_read buffer ~ off ~ len = Body . Writer . write_string response_body ( Bigstringaf . substring ~ off ~ len buffer ) buffer ; Body . Writer . fl... |
let streaming_handler ( ? flush = false ) false response writes reqd = let writes = ref writes in let request_body = Reqd . request_body reqd in Body . Reader . close request_body ; let body = Reqd . respond_with_streaming ~ flush_headers_immediately : flush reqd response in let rec write ( ) = ma... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.