text stringlengths 12 786k |
|---|
let liquidity_baking_escape_ema_zero ( ) = liquidity_baking_escape_ema 0 0 0 100 0 ( ) |
let liquidity_baking_escape_ema_threshold ( ) = liquidity_baking_escape_ema 0 1 812 1 667_667 ( ) |
let liquidity_baking_storage n ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_liquidity_baking_subsidy ( B blk ) >>=? fun subsidy -> let expected_storag... |
let liquidity_baking_balance_update ( ) = Context . init ~ consensus_threshold : 0 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun liquidity_baking -> Context . get_constants ( B blk ) >>=? fun csts -> let sunset = csts . parametri... |
let get_cpmm_result results = match results with | cpmm_result :: _results -> cpmm_result | _ -> assert false |
let get_lqt_result results = match results with | _cpmm_result :: lqt_result :: _results -> lqt_result | _ -> assert false |
let get_address_in_result result = match result with | Apply_results . Origination_result { originated_contracts ; _ } -> ( match originated_contracts with [ c ] -> c | _ -> assert false ) |
let get_balance_updates_in_result result = match result with | Apply_results . Origination_result { balance_updates ; _ } -> balance_updates |
let get_balance_update_in_result result = match get_balance_updates_in_result result with | [ ( Contract _ , Credited balance , Protocol_migration ) ] -> balance | [ _ ; _ ; _ ; _ ; _ ; ( Contract _ , Credited balance , Protocol_migration ) ] -> balance | _ -> assert fal... |
let liquidity_baking_origination_result_cpmm_address ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Context . get_liquidity_baking_cpmm_address ( B blk ) >>=? fun cpmm_address_in_storage -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) ... |
let liquidity_baking_origination_result_cpmm_balance ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_cpmm_result origination_results in let balance_update = get_balance_update... |
let liquidity_baking_origination_result_lqt_address ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_lqt_result origination_results in let address = get_address_in_result resul... |
let liquidity_baking_origination_result_lqt_balance ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let result = get_lqt_result origination_results in let balance_updates = get_balance_updates... |
let liquidity_baking_origination_test_migration ( ) = Context . init 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 1 blk >>=? fun ( _blk , origination_results ) -> let num_results = List . length origination_results in Assert . equal_int ~ loc : __LOC__ ... |
let liquidity_baking_origination_no_tzBTC_mainnet_migration ( ) = Context . init ~ consensus_threshold : 0 ~ level : 1_437_862l 1 >>=? fun ( blk , _contracts ) -> Block . bake_n_with_origination_results 64 blk >>=? fun ( _blk , origination_results ) -> let num_results = List . leng... |
let tests = [ Tztest . tztest " test liquidity baking script hashes " ` Quick liquidity_baking_origination ; Tztest . tztest " test liquidity baking cpmm is originated at the expected address " ` Quick liquidity_baking_cpmm_address ; Tztest . tztest " Init Context " ` Quick generate_init_... |
let print2 x1 x2 = print_s [ % message ( x1 : int ) ( x2 : int ) ] |
let print3 x1 x2 x3 = print_s [ % message ( x1 : int ) ( x2 : int ) ( x3 : int ) ] |
let print2_and_return result x1 x2 = print2 x1 x2 ; result ; ; |
let test2 list_f f sexp_of_result = print_s [ % message " " ~ result ( : list_f [ 1 ] [ 2 ; 3 ] ~ f : result Or_unequal_lengths . t ) ] ; print_s [ % message " " ~ result ( : list_f [ 1 ; 2 ] [ 3 ; 4 ] ~ f : result Or_unequal_lengths . t ) ] ; ; |
let test3 list_f f sexp_of_result = print_s [ % message " " ~ result ( : list_f [ 1 ] [ 2 ; 3 ] [ 4 ; 5 ] ~ f : result Or_unequal_lengths . t ) ] ; print_s [ % message " " ~ result ( : list_f [ 1 ; 2 ] [ 3 ; 4 ] [ 5 ; 6 ] ~ f : result Or_un... |
let assert_eq_s pa pb = let open Lwt_syntax in let * a = pa and * b = pb in assert ( a = b ) ; return_unit |
let assert_err e = e = Error ( ) |
let assert_err_s e = let open Lwt_syntax in let * e = e in assert ( e = Error ( ) ) ; return_unit |
let assert_err_p e = let open Lwt_syntax in let * e = e in assert ( e = Error ( Support . Test_trace . make ( ) ) ) ; return_unit |
module ListGen = struct include Support . Lib . List let rec down n : int t = if n < 0 then [ ] else n :: down ( pred n ) let rec up n i : int t = if i > n then [ ] else i :: up n ( succ i ) let up n = up n 0 end |
module Nth = struct let nth _ = assert ( nth ( up 10 ) 0 = Some 0 ) ; assert ( nth ( up 10 ) 1 = Some 1 ) ; assert ( nth ( up 10 ) 7 = Some 7 ) ; assert ( nth ( up 10 ) 10 = Some 10 ) ; assert ( nth ( up 10 ) 11 = None ) ; assert ( nth ( up 10 ... |
module Last = struct let last _ = assert ( last ( - 1 ) [ ] = - 1 ) ; assert ( last ( - 1 ) ( up 0 ) = 0 ) ; assert ( last ( - 1 ) ( up 10 ) = 10 ) ; ( ) let last_opt _ = assert ( last_opt [ ] = None ) ; assert ( last_opt ( up 0 ) = So... |
module Init = struct let init ( ) = assert ( assert_err @@ init ~ when_negative_length ( ) : ( - 10 ) Fun . id ) ; assert ( init ~ when_negative_length ( ) : 0 Fun . id = Ok [ ] ) ; assert ( init ~ when_negative_length ( ) : 11 Fun . id = Ok ( up 10 ) ) ... |
module FilterSmthg = struct let cond x = x mod 2 = 0 let filter_some ( ) = assert ( filter_some [ ] = [ ] ) ; assert ( filter_some [ None ] = [ ] ) ; assert ( filter_some [ Some 0 ] = [ 0 ] ) ; assert ( let base = up 17 in let left = base |> filter cond in ... |
module ConcatMap = struct let concat_map ( ) = assert ( concat_map Fun . id [ ] = [ ] ) ; assert ( concat_map Fun . id [ [ ] ; [ ] ; [ ] ; [ ] ] = [ ] ) ; assert ( concat_map ( fun _ -> assert false ) [ ] = [ ] ) ; assert ( concat_map ... |
module Combine = struct let combine_error ( ) = assert ( combine ~ when_different_lengths ( ) : [ ] [ 0 ] = Error ( ) ) ; assert ( combine ~ when_different_lengths ( ) : [ 0 ] [ ] = Error ( ) ) ; assert ( combine ~ when_different_lengths ( ) : ( up 100... |
module Partition = struct let cond x = x mod 2 = 0 let partition_result ( ) = assert ( partition_result [ ] = ( [ ] , [ ] ) ) ; assert ( partition_result [ Ok 0 ] = ( [ 0 ] , [ ] ) ) ; assert ( partition_result [ Error 0 ] = ( [ ] , [ 0 ] ... |
module Fold = struct let list = [ 1 ; 2 ; 3 ; 4 ] let list_sum = 10 let test_fold_left_map ( ) = assert ( List . fold_left_map ( fun _ _ -> assert false ) 0 [ ] = ( 0 , [ ] ) ) ; assert ( List . fold_left_map ( fun a b -> ( a + b , b ) ) 0 list = ... |
let ( ) = Alcotest_lwt . run " list - basic " [ ( " nth " , Nth . tests ) ; ( " last " , Last . tests ) ; ( " init " , Init . tests ) ; ( " filter_ " , * FilterSmthg . tests ) ; ( " concat_map_ " , * ConcatMap . tests ) ; ( " comb... |
let space = ' ' |
let tests_string = let test_opt name s mode ~ expected = ( " string : " ^ name , ` Quick , fun ( ) -> let got = Literal_lexer . string mode s in Alcotest . check Alcotest . ( option string ) Caml . __LOC__ expected got ) in let test_one name s mode ~ expected = test_opt name s mo... |
let tests_char = let test_opt name s ~ expected = ( " char : " ^ name , ` Quick , fun ( ) -> let got = Literal_lexer . char s in Alcotest . check ( Alcotest . option Alcotest . string ) Caml . __LOC__ expected got ) in let test name s ~ expected = test_opt name s ~ expected ( ... |
let tests = tests_string @ tests_char |
let bc = Load . bytecode_exe " . . / examples / helloworld . bc " in print_s [ % message " Bytecode executable " ( bc : Load . bytecode_exe ) ] ; [ % expect { | ( " Bytecode executable " ( bc ( ( toc ( ( CODE 10568 ) ( DLPT 0 ) ( DLLS 0 ) ( PRIM 7973... |
let genesis_hash = Block_hash . of_b58check_exn " BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z " |
let genesis_protocol = Protocol_hash . of_b58check_exn " ProtoDemoNoopsDemoNoopsDemoNoopsDemoNoopsDemo6XBoYp " |
let proto = match Registered_protocol . get genesis_protocol with | None -> assert false | Some proto -> proto |
module Proto = ( val proto ) |
let zero = Bytes . create 0 |
let make_empty_chain chain_store n : Block_hash . t Lwt . t = Store . Block . read_block_opt chain_store genesis_hash >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun genesis -> Store . Block . context_exn chain_store genesis >>= fun empty_context -> let header = Store . Block . ... |
let make_multiple_protocol_chain ( chain_store : Store . Chain . t ) ( ~ chain_length : int ) ~ fork_points = Store . Block . read_block_opt chain_store genesis_hash >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun genesis -> Store . Block . context_exn chain_store genesis >... |
let time1 ( f : unit -> ' a ) : ' a * float = let t = Unix . gettimeofday ( ) in let res = f ( ) in let wall_clock = Unix . gettimeofday ( ) . - t in ( res , wall_clock ) |
let time ( ? runs = 1 ) f = if runs < 1 then invalid_arg " time negative arg " else let rec loop cnt sum = if cnt = runs then sum else let ( _ , t ) = time1 f in loop ( cnt + 1 ) ( sum . + t ) in let ( res , t ) = time1 f in let sum = loop 1 t in ( res , sum . / floa... |
let rec repeat f n = if n < 0 then invalid_arg " repeat : negative arg " else if n = 0 then return_unit else f ( ) >>=? fun ( ) -> repeat f ( n - 1 ) |
let linear_predecessor chain_store ( bh : Block_hash . t ) : Block_hash . t option Lwt . t = Store . Block . read_block_opt chain_store bh >|= WithExceptions . Option . get ~ loc : __LOC__ >>= fun b -> Store . Block . read_predecessor_opt chain_store b >|= function | None -> None | So... |
let linear_predecessor_n chain_store ( bh : Block_hash . t ) ( distance : int ) : Block_hash . t option Lwt . t = if distance < 1 then invalid_arg " distance < 1 " else let rec loop bh distance = if distance = 0 then Lwt . return_some bh else linear_predecessor chain_store bh >>= functio... |
let test_pred ( base_dir : string ) : unit tzresult Lwt . t = let size_chain = 1000 in Shell_test_helpers . init_chain base_dir >>= fun store -> let chain_store = Store . main_chain_store store in make_empty_chain chain_store size_chain >>= fun head -> let test_once distance = linear_predecessor_n ... |
let seed = let receiver_id = P2p_peer . Id . of_string_exn ( String . make P2p_peer . Id . size ' r ' ) in let sender_id = P2p_peer . Id . of_string_exn ( String . make P2p_peer . Id . size ' s ' ) in { Block_locator . receiver_id ; sender_id } |
let compute_linear_locator chain_store ~ max_size block = let block_hash = Store . Block . hash block in let header = Store . Block . header block in Block_locator . compute ~ get_predecessor ( : linear_predecessor_n chain_store ) block_hash header ~ size : max_size seed |
let compute_size_locator size_chain = let repeats = 10 . in int_of_float ( ( log ( float size_chain . / repeats ) . / log 2 . ) . - 1 . ) * 10 |
let compute_size_chain size_locator = let repeats = 10 . in int_of_float ( repeats . * ( 2 . ** float ( size_locator + 1 ) ) ) |
let bench_locator base_dir = let size_chain = 80000 in let runs = 10 in let _ = Printf . printf " # runs % i \ n " runs in let exp_limit = compute_size_chain 120 in let _ = Printf . printf " # exp_limit % i \ n " exp_limit in let locator_limit = compute_size_locator size_chain in let _ =... |
let test_protocol_locator base_dir = Shell_test_helpers . init_chain base_dir >>= fun store -> let chain_store = Store . main_chain_store store in let chain_length = 200 in let fork_points = [ 1 ; 10 ; 50 ; 66 ; 150 ] in let further_points = [ 10 ; 50 ; 66 ; 150 ; chain_length... |
let wrap n f = Alcotest_lwt . test_case n ` Quick ( fun _ ( ) -> Lwt_utils_unix . with_tempdir " tezos_test_ " ( fun dir -> f dir >>= function | Ok ( ) -> Lwt . return_unit | Error error -> Format . kasprintf Stdlib . failwith " % a " pp_print_trace error ) ) |
let tests = [ wrap " test pred " test_pred ; wrap " test protocol locator " test_protocol_locator ; ] |
let bench = [ wrap " bench locator " bench_locator ] |
let tests = tests @ if Array . length Sys . argv > 1 then match Sys . argv . ( 1 ) with " -- bench " -> bench | _ -> [ ] else [ ] |
let ( ) = Alcotest_lwt . run ~ argv [ " " ] :|| " tezos - shell " [ ( " locator " , tests ) ] |> Lwt_main . run |
let lock_file = Filename . temp_file " lock_file " " unit_test " let ( ) = Unix . unlink lock_file let % test _ = create lock_file let % test _ = not ( create lock_file ) let % test _ = is_locked lock_file let nolock_file = Filename . temp_file " nolock_file " " unit_test " let... |
let expr2 = Bop ( And , expr , Not ( Const ( F ) ) ) ; ; |
let test_construct _ = assert_equal ( Bop ( And , Bop ( Xor , Const F , Const T ) , Not ( Const F ) ) ) expr2 ; ; |
let test_expr_to_str _ = assert_equal " ( F ^ T ) " ( expr_to_str expr ) ; ; |
let reduced_exp = reduce expr2 ; ; |
let anded = Bop ( And , expr , expr ) ; ; |
let reduced_anded = ( reduce anded ) ; ; |
let test_reduce _ = assert_equal ( Const T ) reduced_exp ; assert_equal ( Const T ) reduced_anded ; ; |
let y = Var ( { name = " y " ; value = F } ) ; ; |
let x = Var ( { name = " x " ; value = F } ) ; ; |
let z = Var ( { name = " z " ; value = T } ) ; ; |
let _ = assign x F ; assign y F ; assign z T ; ; |
let x_and_y = Bop ( And , z , Bop ( Or , ( Not ( z ) ) , Bop ( And , x , y ) ) ) ; ; |
let rec iter_bop_ttbl lst op = match lst with [ ] -> ( ) | x :: xs -> ( let ins = fst x in let res = snd x in let i1 = fst ins in let i2 = snd ins in let expr = op ( Const i1 ) ( Const i2 ) in assert_equal ( eval expr ) ( res ) ) ; iter_bop_ttbl xs op ; ( ) ; ; |
let test_not _ = assert_equal ( eval ( Not ( Const T ) ) ) F ; assert_equal ( eval ( Not ( Const F ) ) ) T ; ; |
let test_and _ = let inputs = [ ( ( F , F ) , F ) ; ( ( F , T ) , F ) ; ( ( T , F ) , F ) ; ( ( T , T ) , T ) ] in iter_bop_ttbl inputs mk_and ; ; |
let test_or _ = let inputs = [ ( ( F , F ) , F ) ; ( ( F , T ) , T ) ; ( ( T , F ) , T ) ; ( ( T , T ) , T ) ] in iter_bop_ttbl inputs mk_or ; ; |
let test_xor _ = let inputs = [ ( ( F , F ) , F ) ; ( ( F , T ) , T ) ; ( ( T , F ) , T ) ; ( ( T , T ) , F ) ] in iter_bop_ttbl inputs mk_xor ; ; |
let test_op_count _ = assert_equal 3 ( op_count x_and_y ) ; ; ) * |
let not_x_and_not_y = Bop ( And , Not x , Not y ) ; ; |
let count = literal_count ( Bop ( And , Const T , x_and_y ) ) ; ; |
let test_demorganize _ = let not_x_or_y = demorganize not_x_and_not_y in assert_equal ( demorganize not_x_or_y ) ( Bop ( And , Not x , Not y ) ) ; assert_equal ( not_x_and_not_y ) ( demorganize ( demorganize not_x_and_not_y ) ) ; ; |
let inputs = [ Var ( { name " = a " ; value = F } ) ; Var ( { name " = b " ; value = F } ) ; Var ( { name " = c " ; value = F } ) ; Var ( { name " = d " ; value = F } ) ; Var ( { name " = e " ; value = F } ) ] ; ; |
let op_tree = make_tree_from_list inputs ; ; |
let op_tree1 = grow_rand_tree 6 inputs ; ; |
let op_tree2 = grow_rand_tree 1 inputs ; ; |
let op_tree3 = grow_rand_tree 2 inputs ; ; |
let full = Var ( { name " = full " ; value = F } ) ; ; |
let ten_minutes = Var ( { name = " ten_minutes " ; value = F } ) ; ; |
let empty = Var ( { name = " empty " ; value = F } ) ; ; |
let five_minutes = Var ( { name = " five_minutes " ; value = F } ) ; ; |
let _ = assign full F ; assign ten_minutes F ; assign empty F ; assign five_minutes F ; ; |
let water_on = Var ( { name = " water_on " ; value = F } ) ; ; |
let agitate = Var ( { name = " agitate " ; value = F } ) ; ; |
let drain = Var ( { name = " drain " ; value = F } ) ; ; |
let start_timer = Var ( { name = " start_timer " ; value = F } ) ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.