text stringlengths 0 601k |
|---|
let test_mylist ctxt = let rec printer f v = match v with | Nil -> " Nil " | Cons ( a , r ) -> Printf . sprintf " Cons ( % s , % s ) " ( f a ) ( printer f r ) in assert_roundtrip ( printer string_of_int ) ( mylist_to_protobuf i1_to_protobuf ) ( mylist_from_protobuf i1_from_protobuf ) ( " \ x08 \ x02 \ x1a \ x1c \ x0a \... |
type v3 = [ ` V3A [ @ key 1 ] ] |
let test_poly_variant ctxt = let printer v = match v with | ` V3A -> " ` V3A " | ` V3B i -> Printf . sprintf " ` V3B ( % d ) " i | ` V3C ( s1 , s2 ) -> Printf . sprintf " ` V3C ( % S , % S ) " s1 s2 in assert_roundtrip printer v3_to_protobuf v3_from_protobuf " \ x08 \ x01 " ` V3A ; assert_roundtrip printer v3_to_protob... |
type r6 = { r6a : [ ` R6A [ @ key 1 ] | ` R6B [ @ key 2 ] ] [ @ key 1 ] ; |
let test_imm_pvariant ctxt = let printer { r6a } = match r6a with ` R6A -> " { r6a = ` R6A } " | ` R6B -> " { r6a = ` R6B } " in assert_roundtrip printer r6_to_protobuf r6_from_protobuf " \ x0a \ x02 \ x08 \ x02 " { r6a = ` R6B } |
type v4 = [ ` V4A [ @ key 1 ] | ` V4B [ @ key 2 ] ] r7a : v4 [ @ key 1 ] [ @ bare ] |
let test_pvariant_bare ctxt = let printer { r7a } = match r7a with ` V4A -> " { r7a = ` V4A } " | ` V4B -> " { r7a = ` V4B } " in assert_roundtrip printer r7_to_protobuf r7_from_protobuf " \ x08 \ x01 " { r7a = ` V4A } |
type r8 = { r8a : [ ` Request [ @ key 1 ] | ` Reply [ @ key 2 ] ] [ @ key 1 ] [ @ bare ] ; r8b : int [ @ key 2 ] ; |
let test_imm_pv_bare ctxt = let printer { r8a ; r8b } = match r8a with | ` Request -> Printf . sprintf " { r8a = ` Request ; r8b = % d } " r8b | ` Reply -> Printf . sprintf " { r8a = ` Reply ; r8b = % d } " r8b in assert_roundtrip printer r8_to_protobuf r8_from_protobuf " \ x08 \ x01 \ x10 \ x2a " { r8a = ` Request ; r... |
let test_variant_optrep ctxt = let printer v5 = match v5 with | V5A io -> ( match io with Some i -> Printf . sprintf " V5A % d " i | None -> " V5A None " ) | V5B sl -> Printf . sprintf " V5B [ % s ] " ( String . concat " ; " sl ) | V5C ia -> Printf . sprintf " V5C [ |% s ] " | ( String . concat " ; " ( List . map strin... |
type r9 = i1 r5 [ @@ deriving protobuf ] |
let test_nonpoly ctxt = let printer { r5a } = Printf . sprintf " { r5a = % d } " r5a in assert_roundtrip printer r9_to_protobuf r9_from_protobuf " \ x0a \ x04 \ x0a \ x02 \ x08 \ x01 " { r5a = 1 } |
type d = int [ @ default 42 ] [ @@ deriving protobuf ] |
let test_default ctxt = assert_roundtrip string_of_int d_to_protobuf d_from_protobuf " " 42 ; assert_roundtrip string_of_int d_to_protobuf d_from_protobuf " \ x08 \ x01 " 1 |
type p = int list [ @ packed ] [ @@ deriving protobuf ] |
let test_packed ctxt = let printer xs = Printf . sprintf " [ % s ] " ( String . concat " ; " ( List . map string_of_int xs ) ) in assert_roundtrip printer p_to_protobuf p_from_protobuf " " [ ] ; assert_roundtrip printer p_to_protobuf p_from_protobuf " \ x0a \ x01 \ x01 " [ 1 ] ; assert_roundtrip printer p_to_protobuf p... |
let test_errors ctxt = let d = Protobuf . Decoder . of_string " " in assert_raises Protobuf . Decoder . ( Failure ( Missing_field " Test_syntax . s " ) ) ( fun ( ) -> s_from_protobuf d ) ; let d = Protobuf . Decoder . of_string " \ x0d \ x00 \ x00 \ xC0 \ x3f " in assert_raises Protobuf . Decoder . ( Failure ( Unexpect... |
let test_skip ctxt = let d = Protobuf . Decoder . of_string " \ x15 \ x00 \ x00 \ xC0 \ x3f " in assert_raises Protobuf . Decoder . ( Failure ( Missing_field " Test_syntax . s " ) ) ( fun ( ) -> s_from_protobuf d ) |
module type Elem = sig type t [ @@ deriving protobuf ] end |
module Collection ( Elem : Elem ) = struct type t = Elem . t list [ @@ deriving protobuf ] end |
let suite = " Test syntax " >::: [ " test_bool " >:: test_bool ; " test_ints " >:: test_ints ; " test_uints " >:: test_uints ; " test_floats " >:: test_floats ; " test_string " >:: test_string ; " test_option " >:: test_option ; " test_list " >:: test_list ; " test_array " >:: test_array ; " test_tuple " >:: test_tuple... |
let show t = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Current_buffer . set_syntax_table t ; let by_class = Class . Table . create ( ) in for i = 0 to 127 do let char = i |> Char . of_int_exn in if Char . is_print char then Hashtbl . add_multi by_class ~ key ( : Current_buffer . syntax_class ( c... |
[ % test_eq : string ] ( unix_quote " " ) { ' ' } ; || [ % test_eq : string ] ( unix_quote " a " ) { ' | a ' } ; | [ % test_eq : string ] ( unix_quote " a ' " ) { ' | a ' ' ' ' } ; \| [ % test_eq : string ] ( unix_quote " a / b /+ share " ) + { | a / b /+ share } ; +| [ % test_eq : string ] ( unix_quote " x \ 000y " ) ... |
for _ = 1 to 1000 do for int = ( - Int . Private . length_preallocated_errnos - 1 ) to Int . Private . length_preallocated_ms - 1 do let t = Int . Private . of_int int in let before_minor = Gc . minor_words ( ) in let before_major = Gc . major_words ( ) in let result = Int . to_result t in let after_minor = Gc . minor_... |
module QCheck_legacy = struct let alpha st = Char . chr ( Char . code ' a ' + Random . State . int st ( Char . code ' z ' - Char . code ' a ' ) ) let string_len len st = let n = len st in assert ( n >= 0 ) ; let b = Buffer . create n in for _i = 0 to n - 1 do Buffer . add_char b ( alpha st ) done ; Buffer . contents b ... |
let priority = QCheck . int_bound 184 |
let priority_g = QCheck . Gen . int_bound 184 |
let ptime_g = let open QCheck . Gen in int_bound ( int_of_float @@ 2 . ** 29 . ) >|= fun n -> n |> Ptime . Span . of_int_s |> Ptime . of_span |
let pp_ptime = function | None -> " < None " > | Some pt -> Rfc3164_Timestamp . encode pt |
let ptime = QCheck . make ~ print : pp_ptime ptime_g |
let valid_data_succeeds = let open QCheck in Test . make ~ count : 100 ~ name " : generating valid data gets a reasonable result " ( triple priority ptime QCheck_legacy . string ) @@ fun ( pri , pt , host ) -> assume ( pt <> None && String . length host > 1 ) ; match pt with | None -> false | Some pt -> let ctx = { tim... |
let invalid_timestamp = let open QCheck in let pp = Print . ( quad int pp_ptime string string ) in Test . make ~ count : 100 ~ name " : parser substitutes the timestamp when it can ' t be parsed " ( make ~ print : pp Gen . ( quad priority_g ptime_g QCheck_legacy . string_g QCheck_legacy . string_g ) ) @@ fun ( pri , va... |
let invalid_data_fails = QCheck . Test . make ~ count : 100 ~ name " : putting in invalid data always fails " QCheck . string @@ fun msg -> let ctx = { timestamp = Ptime . epoch ; hostname = " " ; set_hostname = false } in match decode ~ ctx msg with | Error _ -> true | Ok _ -> false |
let ( ) = let suite = [ invalid_data_fails ; valid_data_succeeds ; invalid_timestamp ] in QCheck_runner . run_tests_main suite |
let test_mode = " test - tabulated - list - mode " |> Symbol . intern |
type entry = { id : string ; s1 : string ; i2 : int ; s3 : string } |
module M = ( val define_derived_mode test_mode [ % here ] ~ docstring " : for testing " ~ mode_line " : Test - mode " ~ parent : Tabulated_list_mode . major_mode ( ) ) |
let t = let format = [ Column . create ~ header " : s1 " ~ pad_right : 3 s1 ; Column . create ~ header " : i2 " ~ sortable : false ( fun x -> Int . to_string_hum ( i2 x ) ) ; Column . create ~ header " : s3 " ~ align_right : true s3 ] in create M . major_mode ~ id_equal : String . equal ~ id_of_record : id ~ id_type : ... |
let entries = [ { id = " b " ; s1 = " b " ; i2 = 1 ; s3 = " y " } ; { id = " a " ; s1 = " a " ; i2 = 2 ; s3 = " z " } ; { id = " c " ; s1 = " c " ; i2 = 3 ; s3 = " x " } ] ; ; |
let draw_and_print ? sort_by entries = let % bind ( ) = Current_buffer . change_major_mode ( major_mode t ) in draw ? sort_by t entries ; printf " % s " ( Current_buffer . contents ( ) |> Text . to_utf8_bytes ) ; return ( ) ; ; Current_buffer . set_temporarily_to_temp_buffer Async ( fun ( ) -> let % bind ( ) = draw_and... |
module Tac_config : P2p_tac . S . CONFIG = struct let trust_weight = 1 . let min_trust = 0 . 1 end |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Tac = P2p_tac . Make ( Node_id ) ( Node ) ( View ) ( Tac_config ) |
let blip bf = let bits = Bloomf . bits bf in let e = 13 . in let _m , k = Bloomf . params bf in let p = Blip . p e k in Blip . flip bits p |
let subs subsl = let bf = Bloomf . create 10 in List . iter ( fun sub -> Bloomf . add bf sub ) subsl ; if do_blip then blip bf else Bloomf . bits bf |
let test_gossip _ctx = printf " \ nTAC GOSSIP \ n \ n " ; let me = Node . init ( u64 23L ) ~ trust : 1 . 0 ~ known : true ~ sim : 1 . 0 ~ subs ( : subs [ " A " ; " B " ; " C " ] ) in let my_xview = View . add ( Node . init ( u64 7L ) ~ trust : 0 . 9 ~ subs ( : subs [ " A " ] ) ) ( View . add ( Node . init ( u64 11L ) ~... |
let suite = " suite " >::: [ " gossip " >:: test_gossip ; ] |
let ( ) = Nocrypto_entropy_unix . initialize ( ) ; run_test_tt_main suite |
module Tac_config : P2p_tac . S . CONFIG = struct let trust_weight = 1 . let min_trust = 0 . 1 end |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Tac = P2p_tac . Make ( Node_id ) ( Node ) ( View ) ( Tac_config ) |
module Io = struct type t = { node_id : Node_id . t ; xview : View . t ; in_chan : Lwt_io . input_channel ; out_chan : Lwt_io . output_channel ; } let init node_id xview in_chan out_chan = { node_id ; xview ; in_chan ; out_chan } let initiate_gossip t dst xchg = pf out " % a # INITIATE_GOSSIP to node % a \ n " Node_id ... |
module Tac_lwt = P2p_tac_lwt . Make ( Node_id ) ( Node ) ( View ) ( Tac ) ( Io ) |
let rec read_chan ch cy node rnode = let % lwt recvd = Lwt_io . read_value ch in let nid = Node . id node in pf out " % a # READ_CHAN \ n " Node_id . pp nid ; pf out " % a # recvd :\ n % a \ n " Node_id . pp nid View . pp recvd ; flush stdout ; let % lwt view = Tac_lwt . respond cy rnode recvd in pf out " % a # recvd :... |
let blip bf = let bits = Bloomf . bits bf in let e = 13 . in let _m , k = Bloomf . params bf in let p = Blip . p e k in Blip . flip bits p |
let subs subsl = let bf = Bloomf . create 10 in List . iter ( fun sub -> Bloomf . add bf sub ) subsl ; if do_blip then blip bf else Bloomf . bits bf |
let _ = Nocrypto_entropy_lwt . initialize ( ) |
let ( ) = let view_len = 8 in let xchg_len = 4 in let period = 0 . 1 in let ( in_ch1 , out_ch2 ) = Lwt_io . pipe ( ) in let ( in_ch2 , out_ch1 ) = Lwt_io . pipe ( ) in let node1 = Node . init ( u64 100L ) ~ trust : 1 . 0 ~ known : true ~ sim : 1 . 0 ~ subs ( : subs [ " A " ; " B " ; " C " ] ) in let xview1 = View . add... |
module Taps_config : P2p_taps . S . CONFIG = struct let min_trust = 0 . 1 let trust_transitivity = 0 . 9 end |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Taps = P2p_taps . Make ( Node_id ) ( Node ) ( View ) ( Taps_config ) |
let me = Node . init ( u64 99L ) ~ trust : 1 . 0 ~ known : true |
let my_view = View . add ( Node . init ( u64 1L ) ~ trust : 0 . 5 ~ known : true ) ( View . add ( Node . init ( u64 2L ) ~ trust : 0 . 9 ~ known : true ) ( View . add ( Node . init ( u64 3L ) ~ trust : 0 . 3 ~ known : true ) ( View . add ( Node . init ( u64 4L ) ~ trust : 0 . 5 ~ known : true ) ( View . add ( Node . in... |
let my_recvd = View . add ( Node . init ( u64 10L ) ~ trust : 0 . 8 ) ( View . add ( Node . init ( u64 20L ) ~ trust : 0 . 6 ) ( View . add ( Node . init ( u64 3L ) ~ trust : 0 . 4 ) View . empty ) ) |
let test_gossip _ctx = printf " \ nTAPS GOSSIP \ n \ n " ; let view = View . empty in let xview = my_view in let ( dst , sent , view ) = Taps . initiate ~ me ~ view ~ xview ~ view_len ~ xchg_len in let recvd = my_recvd in let dst = match dst with | Some dst -> dst | None -> assert_failure " No gossip target " in pf out... |
let suite = " suite " >::: [ " gossip " >:: test_gossip ; ] |
let ( ) = Nocrypto_entropy_unix . initialize ( ) ; run_test_tt_main suite |
module Taps_config : P2p_taps . S . CONFIG = struct let min_trust = 0 . 1 let trust_transitivity = 0 . 9 end |
module Node = P2p . Node . Make ( Node_id ) |
module View = P2p . View . Make ( Node_id ) ( Node ) |
module Taps = P2p_taps . Make ( Node_id ) ( Node ) ( View ) ( Taps_config ) |
module Io = struct type t = { node_id : Node_id . t ; xview : View . t ; in_chan : Lwt_io . input_channel ; out_chan : Lwt_io . output_channel ; } let init node_id xview in_chan out_chan = { node_id ; xview ; in_chan ; out_chan } let initiate_gossip t dst xchg = pf out " % a # INITIATE_GOSSIP to node % a \ n " Node_id ... |
module Taps_lwt = P2p_taps_lwt . Make ( Node_id ) ( Node ) ( View ) ( Taps ) ( Io ) |
let rec read_chan ch cy node rnode = let % lwt recvd = Lwt_io . read_value ch in let nid = Node . id node in pf out " % a # READ_CHAN \ n " Node_id . pp nid ; pf out " % a # recvd :\ n % a \ n " Node_id . pp nid View . pp recvd ; flush stdout ; let % lwt view = Taps_lwt . respond cy rnode recvd in pf out " % a # recvd ... |
let _ = Nocrypto_entropy_lwt . initialize ( ) |
let ( ) = let view_len = 8 in let xchg_len = 4 in let period = 0 . 1 in let ( in_ch1 , out_ch2 ) = Lwt_io . pipe ( ) in let ( in_ch2 , out_ch1 ) = Lwt_io . pipe ( ) in let node1 = Node . init ( u64 100L ) ~ trust : 1 . 0 ~ known : true in let view1 = View . add ( Node . init ( u64 200L ) ~ trust : 0 . 75 ~ known : true... |
let output oc ~ key value = output_string oc ( Printf . sprintf " % s % s \ n " key value ) |
module TestTask = struct type map_init = int ref let map_init _ = ref 0 let map cnt disco in_chan = disco . Task . log ( Printf . sprintf " Mapping % s ( % d bytes ) on % s . . . \ n " disco . Task . input_url disco . Task . input_size disco . Task . hostname ) ; let rec loop ( ) = List . iter ( fun w -> match U . stri... |
let _ = Worker . start ( module TestTask : Task . TASK ) |
let to_raw_context ( b : Block . t ) = Raw_context . prepare b . context ~ level : b . header . shell . level ~ predecessor_timestamp : b . header . shell . timestamp ~ timestamp : b . header . shell . timestamp >|= Environment . wrap_tzresult |
let check_no_dangling_temp_big_map b = to_raw_context b >>=? fun ctxt -> Storage . Big_map . fold ctxt ~ init ( ) : ~ order ` : Sorted ~ f ( : fun id ( ) -> assert ( not ( Lazy_storage_kind . Big_map . Id . is_temp id ) ) ; Lwt . return_unit ) >>= fun ( ) -> Storage . Big_map . fold ctxt ~ init ( ) : ~ order ` : Undefi... |
let call_the_contract b ~ baker ~ src contract param_left param_right = let fee = Alpha_context . Tez . one in let amount = Alpha_context . Tez . zero in let param = Printf . sprintf " Pair ( % s ) % s " param_left param_right in let parameters = Alpha_context . Script . lazy_expr ( Expr . from_string param ) in Op . t... |
let test_temp_big_maps_contract param_left param_right ( ) = Contract_helpers . init ( ) >>=? fun ( b , baker , src , _src2 ) -> Contract_helpers . originate_contract " contracts / temp_big_maps . tz " " { } " src b baker >>=? fun ( contract , b ) -> check_no_dangling_temp_big_map b >>=? fun ( ) -> call_the_contract b ... |
let param_left_values = [ " Left True " ; " Left False " ; " Right { } " ] |
let param_right_values = [ " - 1 " ; " 0 " ; " 1 " ; " 2 " ] |
let tests = List . flatten ( List . map ( fun param_left -> List . map ( fun param_right -> Tztest . tztest ( Printf . sprintf " temp_big_maps ( % s , % s ) " param_left param_right ) ` Quick ( test_temp_big_maps_contract param_left param_right ) ) param_right_values ) param_left_values ) |
module type S = Test . S |
let default_config = Test . default_config Ref . set_temporarily sexp_style To_string_hum ~ f ( : fun ( ) -> print_s [ % sexp ( default_config : Config . t ) ] ) ; [ % expect { | ( ( seed ( Deterministic " an arbitrary but deterministic string " ) ) ( test_count 10000 ) ( shrink_count 10000 ) ( sizes ( 0 1 2 3 4 5 6 7 ... |
let run_exn = Test . run_exn let module M = struct type t = bool option list [ @@ deriving sexp_of ] let quickcheck_generator = Generator . list ( Generator . option Generator . bool ) let quickcheck_shrinker = Shrinker . list ( Shrinker . option Shrinker . bool ) end in let module M_without_shrinker = struct include M... |
let with_sample_exn = Test . with_sample_exn let generator = Generator . list ( Generator . option Generator . bool ) in with_sample_exn generator ~ config { : Test . default_config with test_count = 20 } ~ f ( : fun sample -> Sequence . iter sample ~ f ( : fun value -> Core_kernel . print_s [ % sexp ( value : bool opt... |
let fork_testchain chain_store ( blocks , forked_block ) = let open Lwt_result_syntax in let forked_block_hash = Store . Block . hash forked_block in let genesis_hash = Block_hash . hash_bytes [ Block_hash . to_bytes forked_block_hash ] in let testchain_id = Chain_id . of_block_hash genesis_hash in let head_header = St... |
let test_simple store = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let * ( blocks , head ) = append_blocks ~ should_commit : true ~ should_set_head : true chain_store ~ kind ` : Full 10 in let * _ = fork_testchain chain_store ( blocks , head ) in return_unit |
let test_inner store = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let * ( blocks , head ) = append_blocks ~ should_commit : true ~ should_set_head : true chain_store ~ kind ` : Full 10 in let * ( testchain , blocks , head ) = fork_testchain chain_store ( blocks , head ) in let tes... |
let test_shutdown store = let open Lwt_result_syntax in let chain_store = Store . main_chain_store store in let * ( blocks , head ) = append_blocks ~ should_commit : true ~ should_set_head : true chain_store ~ kind ` : Full 10 in let * ( testchain , blocks , _head ) = fork_testchain chain_store ( blocks , head ) in let... |
let tests = let wrap_test ( s , f ) = let f _ = f in wrap_test ( s , f ) in let test_cases = List . map wrap_test [ ( " forking a test chain " , test_simple ) ; ( " spawning a test chain " , test_inner ) ; ( " shutdown test chain then load it " , test_shutdown ) ; ] in ( " test chain " , test_cases ) |
let f = Ppx_deriving_qcheck . derive_gen ~ loc |
let f ' xs = List . map f xs |> List . concat |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.