text
stringlengths
0
601k
module Mock_protocol : Registration . PROTOCOL = struct include Environment_protocol_T_test . Internal_for_tests . Mock_all_unit let hash = Protocol_hash . hash_string [ " " ] end
module Mock_mockup : Registration . MOCKUP = struct type parameters = unit type protocol_constants = unit let parameters_encoding = Data_encoding . unit let default_parameters = ( ) let protocol_constants_encoding = Data_encoding . unit let default_protocol_constants _ = assert false let default_bootstrap_accounts _ = ...
let mock_mockup_module ( protocol_hash ' : Protocol_hash . t ) : ( module Registration . MOCKUP ) = ( module struct include Mock_mockup let protocol_hash = protocol_hash ' end )
let mock_printer ( ) = let rev_logs : string list ref = ref [ ] in object inherit Tezos_client_base . Client_context . simple_printer ( fun _channel log -> rev_logs := log :: ! rev_logs ; Lwt . return_unit ) method get_logs = List . rev ! rev_logs end
let test_get_registered_mockup_no_env = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup fails when no environment was registered " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Internal_for_tests . Make ( Regis...
let test_get_registered_mockup_not_found = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup fails if the requested protocol is not found " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Internal_for_tests . Make ...
let test_get_registered_mockup_take_alpha = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup returns Alpha if none is specified " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Internal_for_tests . Make ( Registr...
let test_get_registered_mockup_take_requested = let open Lwt_result_syntax in Tztest . tztest " get_registered_mockup returns the requested protocol " ` Quick ( fun ( ) -> let module Registration = Registration . Internal_for_tests . Make ( ) in let module Persistence = Persistence . Internal_for_tests . Make ( Registr...
let ( ) = Alcotest_lwt . run " tezos - mockup " [ ( " persistence " , [ test_classify_does_not_exist ; test_classify_is_file ; test_classify_is_mockup ; test_classify_is_nonempty ; test_classify_is_empty ; test_get_registered_mockup_no_env ; test_get_registered_mockup_not_found ; test_get_registered_mockup_take_alpha ;...
module Hello = struct module Model = struct let name = " hello " type query = unit type response = unit end include Model include Versioned_rpc . Caller_converts . Rpc . Make ( Model ) module V1 = Register ( struct let version = 1 type query = unit [ @@ deriving bin_io ] type response = unit [ @@ deriving bin_io ] let ...
let ( ) = ( List . iter begin List . iter begin
let print_row i row = printf " row % d : [ % s ] s \ n " i ( String . concat " ; " ( List . map ( function
let print_rows rows = List . iteri print_row rows
let print_params_description params = printf " params :\ n " ; List . iteri ( fun i param -> printf " parameter % d :\ n " i ; printf " type : % ld \ n " param . PGOCaml . param_type ) params
let print_row_description results = match results with | None -> printf " this statement returns no data \ n " | Some results -> printf " results :\ n " ; List . iteri ( ) results
let ( ) = let dbh = PGOCaml . connect ( ) in let query = " select current_timestamp " in let name = " timestamp_query " in ignore ( PGOCaml . prepare dbh ~ query ~ name ( ) ) ; let i = ref 0 in PGOCaml . cursor dbh ~ name ~ params [ ] : ( fun row -> incr i ; print_row ! i row ) row ; let params , results = PGOCaml . de...
let test_val ( ? nth = 0 ) ~ decode ~ expected filename ctxt = let file = fixture filename in let res = decode file in let ( public_packet : Packet . t ) = Result . get_ok ( List . nth res nth ) in assert_equal ~ printer [ :% show : Packet . Body . t ] ~ ctxt public_packet . packet expected
module Rsa = struct let public_packet = let expected_public = let n = Z . of_string " 0xfb4be4285f7bf636362c2a86b2680899c30d9d07851850b474e8db8d96743001917984e222e989751930c09c6c88dff8f17ecf8be3d4796bd18946ffae7be00a95055ad9d508225ce3dcec571a804fb15b34dcea1c52ec3720852a0c3c19a5772b7b2fa3c602209df84bd9756cacc040e0e9b5b7...
module Dsa = struct let public_packet = let expected_public = let p = Z . of_string " 0xd93edd8915add1c50daa9f232b17be4b47e8af10d92505dbcd095a332f583c2a64176faa557e896a56e662e8fe72859edce012ca0977dff484a01d969376f46853b4f03a3c23829a2b5b1012b84fbe733d6e384d80ac7406581ae0524f69cf8580d25efd6d976a8756cad44bcbd5c3e34a357f92...
module Elgamal = struct let public_packet = let expected_public = let p = Z . of_string " 0xd56ae8fb6b6bc0fc32e663a7a961607331bd7b41641a048516bfbbb7add148f1b3bffe7ce7544e29cd33c87cafd86b37e49e6d70273e53dcb0f7f3af63655a0c70f11dc4a7d397fbcd70a8666cffc8b6be3506960dcf091881e4faacf6c6530185431a4f96ed10a3e0ef35d9ccd9564c75e6...
let id_packet = Packet . Body . Id " Clement < clement @ test " >
let id_packet2 = Packet . Body . Id " Dimitri Torterat < kra @ diti . me " >
module Test_errors = struct let test_rsa_tag0 ctxt = let file = fixture " rsa_tag0 . pgp " in let res = decode file in let error = Result . get_error ( List . hd res ) in assert_equal ~ ctxt error " Tag 0 " let test_bad_algo ctxt = let file = fixture " bad_pub_algo . pgp " in let res = decode file in let error = Result...
module Signature = struct let signature ~ tag ~ id ( ? version = 4 ) ( ? revocation = [ ] ) ( ? key_flags = [ ] ) validity_period signature_type = let subpackets = List . concat [ key_flags ; validity_period |> Option . to_list |> List . map ( fun validity_period -> Packet . Signature . Subpacket . Key_expiration_time ...
module Id = struct let test_id = test_val ~ nth : 1 ~ decode ~ expected : id_packet " rsa_public . pgp " let test_id2 = test_val ~ nth : 6 ~ decode ~ expected : id_packet2 " revocation_signature . pgp " let suite = [ " Id 1 " >:: test_id ; " Id 2 " >:: test_id2 ] end
let test_marker = test_val ~ decode ~ expected : Packet . Body . Marker " test_marker . pgp "
let suite = [ " Rsa " >::: Rsa . suite ; " Dsa " >::: Dsa . suite ; " Id " >::: Id . suite ; " Signatures " >::: Signature . suite ; " Marker " >:: test_marker ; " Errors " >::: Test_errors . suite ; " Elgamal " >::: Elgamal . suite ]
let pp_value ppf x = Sexp . pp_hum ppf ( sexp_of_t x )
let equal_value ( x : t ) ( y : t ) = x = y
let pp_hstore ppf x = Sexp . pp_hum ppf ( sexp_of_hstore x )
let equal_hstore x y = Sexp . equal ( sexp_of_hstore x ) ( sexp_of_hstore y )
let printer sexp value = sexp value |> Sexp . to_string_hum
let sort_hstore = List . sort ( fun ( k , _ ) ( k ' , _ ) -> String . compare k k ' )
let to_hstore_sorted v = to_hstore v |> Option . map sort_hstore
let to_hstore_sorted_exn v = to_hstore_exn v |> sort_hstore
let pp_inet ppf ( addr , port ) = Format . fprintf ppf " % a :% d " Ipaddr . pp addr port
let equal_inet ( a1 , p1 ) ( a2 , p2 ) = Ipaddr . compare a1 a2 = 0 && p1 = p2
let equal_float x y = match classify_float x , classify_float y with | FP_infinite , FP_infinite -> x = y | FP_nan , FP_nan -> true | _ , _ -> abs_float ( x . - y ) <= epsilon . * ( abs_float x . + abs_float y ) ; ;
module Alcotest_ext = struct let hstore = Alcotest . testable pp_hstore equal_hstore let inet = Alcotest . testable pp_inet equal_inet let value = Alcotest . testable pp_value equal_value let uuid = Alcotest . testable Uuidm . pp Uuidm . equal let our_float = Alcotest . testable Format . pp_print_float equal_float end
let make_test name typ to_value of_value of_value_exn values fail_values = let fail_tests = Alcotest . test_case " null required input " ` Quick ( fun ( ) -> Alcotest . check_raises " non - null conversion " ( Conversion_failure " Expected not - null but got null " ) ( fun ( ) -> ignore ( of_value_exn None ) ) ) :: Lis...
let ( ) = let all_chars = String . init 255 char_of_int in Alcotest . run " Pgx . Value " [ make_test " binary " Alcotest . string of_binary to_binary to_binary_exn [ " " ; " normal string " ; " string with null \ x00 in the midddle " ; all_chars ] [ ] ; make_test " bool " Alcotest . bool of_bool to_bool to_bool_exn [ ...
let time_roundtrip str = Value . of_string str |> Value . to_time_exn
let printer = Time . to_string_abs ~ zone : Time . Zone . utc
let time_testable = Alcotest . testable ( fun ppf t -> Format . pp_print_string ppf ( printer t ) ) Time . equal ; ;
let check_time = Alcotest . check time_testable
let check_string = Alcotest . ( check string )
let test_time_of_string _ = let expected = Time . of_string " 2016 - 03 - 15 19 : 55 : 18 . 123456 - 04 : 00 " in check_time " without TZ " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 . 123456 " ) ; check_time " zulu " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 . 123456Z " ) ; check_time " hour...
let test_time_of_string_no_ms _ = let expected = Time . of_string " 2016 - 03 - 15 19 : 55 : 18 - 04 : 00 " in check_time " without TZ " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 " ) ; check_time " zulu " expected ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18Z " ) ; check_time " hour TZ " expected ( time...
let test_time_conversion_roundtrip _ = let expected_str = " 2016 - 03 - 15 23 : 55 : 18 . 123456Z " in check_string " parse - print " expected_str ( time_roundtrip expected_str |> printer ) ; let expected_time = Time . of_string expected_str in check_time " print - parse " expected_time ( Value . of_time expected_time ...
let time_tests = [ Alcotest . test_case " test time_of_string " ` Quick test_time_of_string ; Alcotest . test_case " test time_of_string no milliseconds " ` Quick test_time_of_string_no_ms ; Alcotest . test_case " test time conversion roundtrip " ` Quick test_time_conversion_roundtrip ] ; ;
let ( ) = Alcotest . run " pgx_async_conversions " [ " time " , time_tests ]
let print_time ( t , tz_offset_s ) = let sec = Ptime . to_float_s t and txt = Ptime . to_rfc3339 t ~ tz_offset_s ~ frac_s : 6 in Printf . sprintf " <% s | Seconds : % f , Offset : % d " > txt sec tz_offset_s ; ;
let value_testable = let print_time value = match Pgx . Value . to_string value with | Some text -> text | None -> " < None " > in let formatter ppf value = Format . pp_print_string ppf ( print_time value ) in Alcotest . testable formatter ( = ) ; ;
let check_value = Alcotest . check value_testable
let test_to_date _ = let check_date = Alcotest . ( check ( triple int int int ) ) in let value = Pgx . Value . of_string " 2021 - 11 - 14 " in let expected = 2021 , 11 , 14 in check_date " check date parsing " expected ( Value . to_date_exn value ) ; let value = Pgx . Value . of_string " 0900 - 06 - 13 " in let expecte...
let test_of_date _ = let date = 2021 , 11 , 14 in let expected = Pgx . Value . of_string " 2021 - 11 - 14 " in check_value " check date rendering " expected ( Value . of_date date ) ; let date = 900 , 6 , 13 in let expected = Pgx . Value . of_string " 0900 - 06 - 13 " in check_value " dates with leading zeros render pr...
let date_tests = [ Alcotest . test_case " of_date renders a Ptime date to a Pgx Value " ` Quick test_of_date ; Alcotest . test_case " to_date parses a Pgx Value to a Ptime date " ` Quick test_to_date ] ; ;
let check_time = let compare_times ( t1 , o1 ) ( t2 , o2 ) = let tf1 = Ptime . to_float_s t1 and tf2 = Ptime . to_float_s t2 in abs_float ( tf1 . - tf2 ) < 1 . 0e - 6 && o1 = o2 in let time_testable = Alcotest . testable ( fun ppf t -> Format . pp_print_string ppf ( print_time t ) ) compare_times in Alcotest . check ti...
let test_time_of_string _ = let hour = 3600 in let hourf = 3600 . in let to_pt x = Ptime . of_float_s x |> Option . value ~ default : Ptime . min in check_time " minimum time parses " ( Ptime . min , 0 ) ( Value . time_of_string " 0000 - 01 - 01T00 : 00 : 00Z " ) ; let pt = to_pt ( 12 . . * hourf ) in check_time " time...
let time_roundtrip str = Value . of_string str |> Value . to_time_exn
let test_time_tz_handling _ = let utc_t , tz_offset_s = Value . time_of_string " 2016 - 03 - 15 19 : 55 : 18 - 04 : 00 " in check_time " without TZ " ( utc_t , 0 ) ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18 " ) ; check_time " zulu " ( utc_t , 0 ) ( time_roundtrip " 2016 - 03 - 15 23 : 55 : 18Z " ) ; check_time " ho...
let test_time_conversion_roundtrip _ = let print_time ( t , tz_offset_s ) = Ptime . to_rfc3339 t ~ tz_offset_s ~ frac_s : 6 in let expected_str = " 2016 - 03 - 15T23 : 55 : 18 . 123456Z " in Alcotest . ( check string ) " parse - print " expected_str ( time_roundtrip expected_str |> print_time ) ; let t , tz_offset_s = ...
let time_tests = [ Alcotest . test_case " test time_of_string " ` Quick test_time_of_string ; Alcotest . test_case " test time_of_string time zone handling " ` Quick test_time_tz_handling ; Alcotest . test_case " test time conversion roundtrip " ` Quick test_time_conversion_roundtrip ] ; ;
let ( ) = Alcotest . run " pgx_async_conversions " [ " date " , date_tests ; " time " , time_tests ]
let count = Some 1000
let test_flush ( ) = let l = QCheck2 . Gen . generate ~ n ( : Option . value ~ default : 1 count ) ( QCheck2 . Gen . pair Generators . filter_state_with_operation_gen QCheck2 . Gen . bool ) in List . iter_es ( fun ( ( filter_state , ( ( op_info : manager_op_info ) , pkh ) ) , with_validation_state ) -> let filter_state...
let ( ) = Alcotest_lwt . run " Plugin " [ ( " on_flush " , [ Tztest . tztest " [ on_flush ~ validation_state . . . ] yields an empty state " ` Quick test_flush ; ] ) ; ] |> Lwt_main . run
let show ( ) = print_s [ % message " " ~ point ( : get ( ) : Position . t ) ] Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> show ( ) ; [ % expect { | ( point 1 ) } ] ; | print_s [ % sexp ( Current_buffer . get ( ) : Buffer . t ) ] ; insert " foo " ; show ( ) ; [ % expect { | " #< buffer * temp - buf...
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 . Stubs ( S ) open M let test_passing_pointers _ = assert_equal ~ msg " : Passing pointers to various numeric types " ~ printer : string_of_int ( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + ...
let test_pointer_assignment_with_primitives _ = let open Signed in let open Unsigned in let p_char = allocate char ' 1 ' and p_uchar = allocate uchar ( UChar . of_int 2 ) and p_bool = allocate bool false and p_schar = allocate schar 3 and p_float = allocate float 4 . 0 and p_double = allocate double 5 . 0 and p_short =...
let test_dereferencing_pointers_to_incomplete_types _ = begin assert_raises IncompleteType ( fun ( ) -> !@ null ) ; assert_raises IncompleteType ( fun ( ) -> ( !@ from_voidp ( structure " incomplete " ) null ) ) ; assert_raises IncompleteType ( fun ( ) -> ( !@ from_voidp ( union " incomplete " ) null ) ) ; end
let test_writing_through_pointer_to_abstract_type _ = let module Array = CArray in let arra = Array . make int 2 in let arrb = Array . make int 2 in let absptr a = from_voidp ( abstract ~ name " : absptr " ~ size ( : 2 * sizeof int ) ~ alignment ( : alignment ( array 2 int ) ) ) ( to_voidp ( Array . start a ) ) in let ...
let test_reading_and_writing_global_value _ = let ptr = foreign_value " global " int ~ from : testlib in let ptr ' = foreign_value " global " int ~ from : testlib in assert_equal ( !@ ptr ) 100 ; ptr <-@ 200 ; assert_equal ( !@ ptr ) 200 ; assert_equal ( !@ ptr ' ) 200 ; ptr ' <-@ 100 ; assert_equal ( !@ ptr ) 100 ; as...
let test_reading_strings _ = let p = allocate_n char 26 in begin StringLabels . iteri " abcdefghijklmnoprwstuvwxyz " ~ f ( : fun i c -> ( p +@ i ) <-@ c ) ; assert_equal ( string_from_ptr p 5 ) " abcde " ; assert_equal ( string_from_ptr p 26 ) " abcdefghijklmnoprwstuvwxyz " ; assert_equal ( string_from_ptr p 0 ) " " ; ...
let test_pointer_arithmetic _ = let module Array = CArray in let arr = Array . of_list int [ 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ] in let p = Array . start arr in for i = 0 to 7 do assert_equal ( !@ p +@ i ) ( succ i ) done ; let twoints = structure " s " in let i1 = field twoints " i " int in let i2 = field twoints " j " in...
let test_pointer_comparison _ = let canonicalize p = let buf = allocate_n ~ count : 1 ( ptr void ) in buf <-@ ( to_voidp p ) ; !@ buf in let ( ) < l r = ptr_compare l r < 0 and ( ) > l r = ptr_compare l r > 0 and ( ) = l r = ptr_compare l r = 0 in let p = allocate int 10 in let p ' = from_voidp int ( to_voidp p ) in as...
let test_pointer_differences _ = let canonicalize p = let buf = allocate_n ~ count : 1 ( ptr void ) in buf <-@ ( to_voidp p ) ; !@ buf in let s = structure " s " in let ( ) -: ty label = field s label ty in let i = int -: " i " in let j = array 17 char -: " j " in let k = double -: " k " in let l = char -: " l " in let...
let test_raw_pointers _ = let p : float ptr = allocate double 1 . 0 in let p ' = p +@ 3 in let praw = raw_address_of_ptr ( to_voidp p ) in let praw ' = raw_address_of_ptr ( to_voidp p ' ) in assert_equal praw ' Nativeint . ( add praw ( of_int ( 3 * sizeof double ) ) )
let suite = " Pointer tests " >::: [ " passing pointers ( foreign ) " >:: Foreign_tests . test_passing_pointers ; " passing pointers ( stubs ) " >:: Stub_tests . test_passing_pointers ; " passing pointers to pointers ( foreign ) " >:: Foreign_tests . test_passing_pointers_to_pointers ; " passing pointers to pointers ( ...
let _ = run_test_tt_main suite
module Node = P2p . Node . Make ( Node_id )
module Group = P2p . Group . Make ( Group_id )
module View = P2p . View . Make ( Node_id ) ( Node )
module Ringcast = P2p_ringcast . Make ( Node_id ) ( Node ) ( View ) ( Msg_id )
module Poldercast = P2p_poldercast . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast )
let test_sub _ctx = printf " \ nPOLDERCAST SUB \ n " ; let sub = Sub . add ( Group . init ( u64 11L ) ) ( ) ( Sub . add ( Group . init ( u64 23L ) ) ( ) ( Sub . add ( Group . init ( u64 37L ) ) ( ) ( Sub . add ( Group . init ( u64 41L ) ) ( ) ( Sub . empty ) ) ) ) in let n23 = Node . init ( u64 23L ) in let _bits = Sub...
let suite = " suite " >::: [ " sub " >:: test_sub ; ]
let ( ) = Nocrypto_entropy_unix . initialize ( ) ; run_test_tt_main suite
module Node = P2p . Node . Make ( Node_id )
module Group = P2p . Group . Make ( Group_id )
module View = P2p . View . Make ( Node_id ) ( Node )
module Ringcast = P2p_ringcast . Make ( Node_id ) ( Node ) ( View ) ( Msg_id )
module Poldercast = P2p_poldercast . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast )
let sent_msgs = Hashtbl . create 3
module UView = struct type t = { rings : ( Group_id . t , View . t ) Hashtbl . t ; } let create = { rings = Hashtbl . create 10 } let set_ring t gid view = Hashtbl . replace t . rings gid view let view t = Hashtbl . fold ( fun _gid view uview -> View . union uview view ) t . rings View . empty end
module Io = struct module IoMap = Map . Make ( Node ) type t = { group : Group . t ; me : Node . t ; uview : UView . t ; io : ( Lwt_io . input_channel * Lwt_io . output_channel ) IoMap . t ; } let init me uview = ( fun group -> { group ; me ; uview ; io = IoMap . empty } ) let get_chan t dst = match IoMap . find_opt ds...
module Ringcast_lwt = P2p_ringcast_lwt . Make ( Node_id ) ( Node ) ( View ) ( Msg_id ) ( Ringcast ) ( Io )
module Poldercast_lwt = P2p_poldercast_lwt . Make ( Node_id ) ( Group_id ) ( Node ) ( Group ) ( View ) ( Msg_id ) ( Ringcast ) ( Io ) ( Ringcast_lwt ) ( Poldercast )
let _ = Nocrypto_entropy_lwt . initialize ( )