text stringlengths 12 786k |
|---|
let pr_num = den - pr_ema_weight |
let expected_qr_num participation_ema = let participation_ema = Int32 . to_int participation_ema in let participation_ema = participation_ema * den / percent_mul in Float . ( of_int qr_min_num . + of_int participation_ema . * ( of_int qr_max_num . - of_int qr_min_num ) . / of_int den ) |
let protos = Array . map ( fun s -> Protocol_hash . of_b58check_exn s ) [ | " ProtoALphaALphaALphaALphaALphaALphaALpha61322gcLUGH " ; " ProtoALphaALphaALphaALphaALphaALphaALphabc2a7ebx6WB " ; " ProtoALphaALphaALphaALphaALphaALphaALpha84efbeiF6cm " ; " ProtoALphaALphaALphaALphaALphaALpha... |
let assert_period_kind expected_kind kind loc = if Stdlib . ( expected_kind = kind ) then return_unit else Alcotest . failf " % s - Unexpected voting period kind - expected % a , got % a " loc Voting_period . pp_kind expected_kind Voting_period . pp_kind kind |
let assert_period_index expected_index index loc = if expected_index = index then return_unit else Alcotest . failf " % s - Unexpected voting period index - expected % ld , got % ld " loc expected_index index |
let assert_period_position expected_position position loc = if position = expected_position then return_unit else Alcotest . failf " % s - Unexpected voting period position blocks - expected % ld , got % ld " loc expected_position position |
let assert_period_remaining expected_remaining remaining loc = if remaining = expected_remaining then return_unit else Alcotest . failf " % s - Unexpected voting period remaining blocks - expected % ld , got % ld " loc expected_remaining remaining |
let assert_period ? expected_kind ? expected_index ? expected_position ? expected_remaining b loc = Context . Vote . get_current_period ( B b ) >>=? fun { voting_period ; position ; remaining } -> ( if Option . is_some expected_kind then assert_period_kind ( WithExceptions . Option . ge... |
let assert_ballots expected_ballots b loc = Context . Vote . get_ballots ( B b ) >>=? fun ballots -> Assert . equal ~ loc ballots_equal " Unexpected ballots " ballots_pp ballots expected_ballots |
let assert_empty_ballots b loc = assert_ballots ballots_zero b loc >>=? fun ( ) -> Context . Vote . get_ballot_list ( B b ) >>=? function | [ ] -> return_unit | _ -> failwith " % s - Unexpected ballot list " loc |
let mk_contracts_from_pkh pkh_list = List . map Contract . implicit_contract pkh_list |
let get_delegates_and_power_from_listings b = Context . Vote . get_listings ( B b ) >|=? fun l -> ( mk_contracts_from_pkh ( List . map fst l ) , List . map snd l ) |
let get_power b delegates loc = Context . Vote . get_listings ( B b ) >>=? fun l -> List . map_es ( fun delegate -> Context . Contract . pkh delegate >>=? fun pkh -> match List . find_opt ( fun ( del , _ ) -> del = pkh ) l with | None -> failwith " % s - Missing delegate " l... |
let assert_listings_not_empty b ~ loc = Context . Vote . get_listings ( B b ) >>=? function | [ ] -> failwith " Unexpected empty listings ( % s ) " loc | _ -> return_unit |
let bake_until_first_block_of_next_period ? policy b = Context . Vote . get_current_period ( B b ) >>=? fun { remaining ; _ } -> Block . bake_n ? policy Int32 . ( add remaining one |> to_int ) b |
let context_init = Context . init ~ blocks_per_cycle : 4l ~ blocks_per_voting_period : 4l ~ consensus_threshold : 0 ~ endorsing_reward_per_slot : Tez . zero ~ baking_reward_bonus_per_slot : Tez . zero ~ baking_reward_fixed_portion : Tez . zero |
let test_successful_vote num_delegates ( ) = let open Alpha_context in let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , _ ) -> assert_empty_ballots b __LOC__ >>=? fun ( ) -> assert_period ~ ... |
let get_smallest_prefix_voters_for_quorum active_delegates active_power participation_ema = let expected_quorum = expected_qr_num participation_ema in List . fold_left ( fun acc v -> Int64 . ( add v acc ) ) 0L active_power |> fun active_power_sum -> let rec loop delegates power sum selected = match (... |
let get_expected_participation_ema power voter_power old_participation_ema = let get_updated_participation_ema old_participation_ema participation = ( ( pr_ema_weight * Int32 . to_int old_participation_ema ) + ( pr_num * participation ) ) / den in List . fold_left ( fun acc v -> Int64 . ( a... |
let test_not_enough_quorum_in_exploration num_delegates ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , delegates ) -> let open Alpha_context in assert_period ~ expected_kind : Proposal b __... |
let test_not_enough_quorum_in_promotion num_delegates ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , delegates ) -> assert_period ~ expected_kind : Proposal b __LOC__ >>=? fun ( ) ->... |
let test_multiple_identical_proposals_count_as_one ( ) = context_init 1 >>=? fun ( b , delegates ) -> assert_period ~ expected_kind : Proposal b __LOC__ >>=? fun ( ) -> let proposer = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd delegates in Op . proposals ( B b ) p... |
let test_supermajority_in_proposal there_is_a_winner ( ) = let min_proposal_quorum = 0l in let initial_balance = 1L in context_init ~ min_proposal_quorum ~ initial_balances [ : initial_balance ; initial_balance ; initial_balance ] 10 >>=? fun ( b , delegates ) -> Context . get_constants (... |
let test_quorum_in_proposal has_quorum ( ) = let total_tokens = 32_000_000_000_000L in let half_tokens = Int64 . div total_tokens 2L in context_init ~ initial_balances [ : 1L ; half_tokens ; half_tokens ] 3 >>=? fun ( b , delegates ) -> Context . get_constants ( B b ) >>=? fun { ... |
let test_supermajority_in_exploration supermajority ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / 100 ) ) in context_init ~ min_proposal_quorum 100 >>=? fun ( b , delegates ) -> let del1 = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth delegates 0 ... |
let test_no_winning_proposal num_delegates ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , _ ) -> get_delegates_and_power_from_listings b >>=? fun ( delegates_p1 , _power_p1 ) -> let... |
let test_quorum_capped_maximum num_delegates ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , delegates ) -> Context . Vote . set_participation_ema b 100_00l >>= fun b -> Context . get... |
let test_quorum_capped_minimum num_delegates ( ) = let min_proposal_quorum = Int32 . ( of_int @@ ( 100_00 / num_delegates ) ) in context_init ~ min_proposal_quorum num_delegates >>=? fun ( b , delegates ) -> Context . Vote . set_participation_ema b 0l >>= fun b -> Context . get_cons... |
let get_voting_power block pkhash = let ctxt = Context . B block in Context . get_voting_power ctxt pkhash |
let test_voting_power_updated_each_voting_period ( ) = let init_bal1 = 80_000_000_000L in let init_bal2 = 48_000_000_000L in let init_bal3 = 40_000_000_000L in context_init ~ initial_balances [ : init_bal1 ; init_bal2 ; init_bal3 ] 3 >>=? fun ( genesis , contracts ) -> let con1 = WithExce... |
let test_voting_period_pp ( ) = let vp = Voting_period_repr . { index = Int32 . of_int 123 ; kind = Proposal ; start_position = Int32 . of_int 321 ; } in Assert . equal ~ loc : __LOC__ ( = ) " Unexpected pretty printing of voting period " Format . pp_print_string ( Format . ... |
let tests = [ Tztest . tztest " voting successful_vote " ` Quick ( test_successful_vote 137 ) ; Tztest . tztest " voting cooldown , not enough quorum " ` Quick ( test_not_enough_quorum_in_exploration 245 ) ; Tztest . tztest " voting promotion , not enough quorum " ` Quick ( ... |
type block = int ref Heap_block . t [ @@ deriving sexp_of ] |
let block int = ref int |> Heap_block . create_exn |
let print t = print_s [ % sexp ( t : int ref t ) ] for len = 0 to 3 do print_s [ % sexp ( length ( create ~ len ) : int ) ] done ; [ % expect { | 0 1 2 3 } ] | ; ; let t = create ~ len : 1 in print t ; [ % expect { | ( ( ) ) } ] ; | set t 0 N... |
let create ( ) = create ( module Int ) |
let data int = ref int |> Heap_block . create_exn |
type data = int ref Heap_block . t [ @@ deriving sexp_of ] let t = create ( ) in let print_mem i = print_s [ % message ( i : int ) ~ mem ( : mem t i : bool ) ] in let key = 13 in print_mem key ; [ % expect { | ( ( i 13 ) ( mem false ) ) } ] ; | add_exn t ~ k... |
type contents = int ref [ @@ deriving sexp_of ] |
type heap_block = contents Heap_block . t [ @@ deriving sexp_of ] |
let heap_block name int = let b = ref int |> Heap_block . create_exn in Gc . Expert . add_finalizer_last b ( fun _ -> print_s [ % message " finalized " name ] ) ; b ; ; |
let print t = print_s [ % message " " ~ _ ( : t : int ref t ) ~ is_some ( : is_some t : bool ) ~ get ( : get t : contents Heap_block . t option ) ] ; ; let t = create ( ) in print t ; [ % expect { | ( ( ) ( is_some false ) ( get ( ) ) ) } ] ; ... |
module TestWsIteratee = Websockets . Wsprotocol ( Test . StringMonad ) |
module I = Iteratees . Iteratee ( Test . StringMonad ) |
let test_strings = [ " \ x81 \ x05 \ x48 \ x65 \ x6c \ x6c \ x6f " ; " \ x01 \ x03 \ x48 \ x65 \ x6c " ; " \ x80 \ x02 \ x6c \ x6f " ; " \ x82 \ x7F \ x0000000000010000 " ; " \ x82 \ x7F \ x0000000000010000 " ] |
let test_wsframe ( ) = let frame = wsframe ( writer Test . StringMonad . strwr " foo " ) in let unframe = wsunframe ( writer Test . StringMonad . strwr " bar " ) in test_strings |> List . iter ( fun str -> let x = enum_1chunk ( Test . StringMonad . getstr ( enum_1chunk str ... |
let test_wsframe_old ( ) = let frame = wsframe_old ( writer Test . StringMonad . strwr " foo " ) in let unframe = wsunframe_old ( writer Test . StringMonad . strwr " bar " ) in test_strings |> List . iter ( fun str -> let x = enum_1chunk ( Test . StringMonad . getstr ( enum... |
let test_wsunframe ( ) = let unframe = wsunframe ( writer Test . StringMonad . strwr " foo " ) in assert_equal " Hello " ( Test . StringMonad . getstr ( enum_1chunk test_mask_str unframe ) ) ; for i = 1 to 10 do assert_equal " Hello " ( Test . StringMonad . getstr ( en... |
let test_wsunframe_old ( ) = let unframe = wsunframe_old ( writer Test . StringMonad . strwr " foo " ) in assert_equal " HelloThere " ( Test . StringMonad . getstr ( enum_1chunk test_old_str unframe ) ) ; for i = 1 to 10 do assert_equal " HelloThere " ( Test . StringMonad ... |
let test = " test_websockets " >::: [ " test_wsframe " >:: test_wsframe ; " test_wsunframe " >:: test_wsunframe ; " test_wsframe_old " >:: test_wsframe_old ; " test_wsunframe_old " >:: test_wsunframe_old ] |
let print_expr expr = Pprintast . string_of_structure [ % str let ( ) = [ % e expr ] ] |> print_string ; ; Ppx_let_expander . expand ~ modul : None Bind [ % expr while MY_CONDITION do MY_BODY done ] |> print_expr ; [ % expect { | let ( ) = let rec __let_syntax_loop__001_ (... |
let prev = { | assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Set . length t . by_constant_usage ) ) ; assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Hashtbl . length t . bucket_id_to_keys ) ) ) } | ; ; |
let next = { | assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Set . length t . by_constant_usage ) ) ; assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Hashtbl . length t . bucket_id_to_keys ) ) } | ; ; let % bind ( ) = p... |
let prev = { | assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Set . length t . by_constant_usage ) ) ; assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Hashtbl . length t . bucket_id_to_keys ) ) ) } | ; ; |
let next = { | assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Set . length t . by_constant_usage ) ) ; assert ( Int . ( = ) ( Set . length t . by_varying_usage ) ( Hashtbl . length t . bucket_id_to_keys ) ) } | ; ; let % bind ( ) = p... |
let show_all ( ) = print_s [ % sexp ( Frame . window_list ( ) : t list ) ] show_all ( ) ; [ % expect { | ( " #< window 1 on * scratch " ) *> } ] ; | return ( ) ; ; |
let show t = print_s [ % message " " ~ body_height ( : try_with ( fun ( ) -> body_height_exn t ) : int Or_error . t ) ~ buffer ( : try_with ( fun ( ) -> buffer_exn t ) : Buffer . t Or_error . t ) ~ height ( : try_with ( fun ( ) -> height_exn t ) : int Or_error... |
let t = List . hd_exn ( Frame . window_list ( ) ) show t ; [ % expect { | ( ( body_height ( Ok 8 ) ) ( buffer ( Ok " #< buffer * scratch " ) ) *> ( height ( Ok 9 ) ) ( is_live ( Ok true ) ) ( point ( Ok 1 ) ) ( width ( Ok 10 ) ) ) } ]... |
let sort_results r = let cmp x y = let res = Stdlib . compare ( fst x ) ( fst y ) in if res = 0 then Stdlib . compare ( snd x ) ( snd y ) else res in List . sort ( cmp ) r |
let res_to_string r = List . rev r |> List . map ( fun x -> fst x ) |> List . map ( string_of_int ) |> List . fold_left ( fun a x -> a ^ x ^ " , " ) " " |
let t2 = [ - 525 ; - 765 ; 990 ; 457 ; - 841 ; - 446 ; - 407 ; 386 ; - 433 ; - 145 ; 370 ; - 133 ; - 170 ; 348 ; - 532 ; 328 ; 306 ; - 325 ; - 856 ; - 131 ; 971 ; 266 ; - 88 ; - 608 ; - 274 ; 539 ; 10 ; - 367 ; 389 ... |
let r2 = " - 525 , - 765 , - 841 , - 532 , - 856 , - 608 , - 745 , - 983 , - 883 , - 903 , - 818 , - 790 , - 680 , " ^ " - 683 , - 898 , - 900 , - 160 , - 803 , " |
let t3 = [ - 688 ; 288 ; - 953 ; - 376 ; - 521 ; 480 ; - 314 ; 723 ; 428 ; 260 ; - 804 ; - 915 ; 471 ; 990 ; - 243 ; - 230 ; - 684 ; - 694 ; 682 ; 948 ; 404 ; - 474 ; - 704 ; 746 ; 886 ; 634 ; 92 ; - 87 ; 778 ; - 42... |
let r3 = " - 688 , - 953 , - 521 , - 314 , - 804 , - 915 , - 684 , - 694 , - 704 , - 87 , - 424 , - 883 , - 463 , " ^ " - 408 , - 938 , - 641 , - 978 , - 921 , - 909 , - 745 , - 693 , - 612 , - 475 , - 173 , - 487 ... |
let t4 = [ - 776 ; 271 ; 540 ; - 580 ; - 710 ; 803 ; 690 ; 980 ; 611 ; - 305 ; 252 ; - 404 ; - 377 ; 544 ; - 982 ; - 577 ; - 792 ; 139 ; 574 ; - 107 ; 752 ; - 108 ; - 326 ; 354 ; - 339 ; - 323 ; - 317 ; - 571 ; - 995... |
let tests = [ " winnow0 " >:: ( fun _ -> assert_equal " " ( winnow 1 [ ] |> res_to_string ) ) ; " winnow1 " >:: ( fun _ -> assert_equal " 1 , " ( winnow 1 [ 1 ] |> res_to_string ) ) ; " winnow2 " >:: ( fun _ -> assert_equal " 1 , 2 , 3 , 4... |
let test_decoder ctxt = let d = Decoder . of_bytes ( Bytes . of_string " \ x01 " ) in assert_equal ~ printer : Int64 . to_string 1L ( Decoder . varint d ) ; let d = Decoder . of_string " \ xac \ x02 " in assert_equal ~ printer : Int64 . to_string 300L ( Decoder . varint d )... |
let test_encoder ctxt = let printer s = Printf . sprintf " % S " s in let e = Encoder . create ( ) in Encoder . varint 1L e ; assert_equal ~ printer " \ x01 " ( Bytes . to_string ( Encoder . to_bytes e ) ) ; let e = Encoder . create ( ) in Encoder . varint 300L e ; a... |
let test_overflow ctxt = if Sys . word_size = 32 then assert_raises Decoder . ( Failure ( Overflow " " ) ) ( fun ( ) -> Decoder . int_of_int32 " " 0x7fffffffl ) else assert_equal ( - 1 ) ( Decoder . int_of_int32 " " 0xffffffffl ) ; assert_raises Decoder . ( Fail... |
let test_truncate ctxt = assert_equal ( - 1 ) ( Decoder . int_of_int64 " " ( - 1L ) ) |
let suite = " Test wire format " >::: [ " test_decoder " >:: test_decoder ; " test_encoder " >:: test_encoder ; " test_overflow " >:: test_overflow ; " test_truncate " >:: test_truncate ; ] |
let test_loop loop_limit jump_out = with_return ( fun { return } -> for i = 0 to loop_limit do if i = jump_out then return ( ` Jumped_out i ) done ; ` Normal ) ; ; |
let ( = ) = Poly . equal |
let test_nested outer inner = with_return ( fun { return = return_outer } -> if outer = ` Outer_jump then return_outer ` Outer_jump ; let inner_res = with_return ( fun { return = return_inner } -> if inner = ` Inner_jump_out_completely then return_outer ` Inner_jump ; if inner = ` Inn... |
let test_loop loop_limit jump_out = with_return_option ( fun { return } -> for i = 0 to loop_limit do if i = jump_out then return ( ` Jumped_out i ) done ) ; ; |
let ( = ) = Poly . equal |
let recv_from_page e = let data = ( Message . Ev . data ( Ev . as_type e ) : Jstr . t ) in match Jstr . to_string data with | " Work " ! -> Worker . G . post Jstr . ( v " Page said : " + data + v " I say Revolt " ) ! | _ -> assert false |
let worker_main ( ) = Console . ( log [ str " Worker hello " ] ) ; ! let msg = Ev . next Message . Ev . message G . target in let _ = Fut . map recv_from_page msg in ( ) |
let spawn_worker ( ) = try Ok ( Worker . create ( Jstr . v " test_worker . js " ) ) with |
let recv_from_worker ~ view e = let data : Jstr . t = Message . Ev . data ( Ev . as_type e ) in El . set_children view [ El . p El . [ txt Jstr . ( v " Worker says : " + data ) ] ] |
let page_main ( ) = let h1 = El . h1 [ El . txt ' " Test workers " ] in let info = El . p [ El . strong [ El . txt ' " Note . " ] ; El . txt ' " Doesn ' t work over the file :// protocol . " ] in let view = El . div [ ] in El . set_children ( Document... |
let main ( ) = if Worker . ami ( ) then worker_main ( ) else page_main ( ) |
let ( ) = main ( ) |
let _ = Printexc . record_backtrace true |
type a = { a : float ; a_wrap : a Ocsigen_wrap . wrapper } wrapper |
let a_wrap ( ) = Ocsigen_wrap . create_wrapper ( fun t -> { a = t . a . + 1 . ; a_wrap = Ocsigen_wrap . empty_wrapper } empty_wrapper ) empty_wrapper |
let a i = { a = i ; a_wrap = a_wrap ( ) } |
let va = a 3 . 14 |
let _ , v = Ocsigen_wrap . wrap va |
let ( ) = assert ( v . a . - 4 . 14 < 0 . 0001 ) 0001 |
let va = [ [ [ [ [ [ 1 , [ 3 . 1 , a 3 . 14 ] 14 ] 14 , a 35 . 1 ] 1 ] 1 ] 1 ] 1 ] 1 |
let _ , _ = Ocsigen_wrap . wrap va |
type b = { b : string ; ba : a ; b ' : string ; b_wrap : b Ocsigen_wrap . wrapper } wrapper |
let b_wrap ( ) = Ocsigen_wrap . create_wrapper ( fun t -> t . b , t . ba ) ba |
let b s f = { b = s ; b ' = s ; b_wrap = b_wrap ( ) ; ba = a f } f |
let vb = b tst_string 3 . 14 |
let _ , vb ' = Ocsigen_wrap . wrap vb |
let _ = assert ( let t , f = Obj . magic vb ' in t == tst_string && f . - 4 . 14 < 0 . 0001 ) 0001 |
let _ , vb ' ' = Ocsigen_wrap . wrap [ 2 , [ 1 . , [ vb , 4 , ref 0 ] 0 , ref 42 ] 42 ] 42 |
let ( ) = match vb ' ' with | [ ( 2 , [ ( 1 . , [ ( vb ' , 4 , { contents = 0 } 0 ) 0 ] 0 , { contents = 42 } 42 ) 42 ] 42 ) 42 ] 42 -> assert ( let t , f = Obj . magic vb ' in t == tst_string && f . - 4 . 14 < 0 . 0001 ) 0001 |... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.