text stringlengths 12 786k |
|---|
let test_transfer_n ctxt src dest = Token . transfer_n ctxt src dest >>=? fun ( ctxt1 , bal_updates1 ) -> List . fold_left_es ( fun ( ctxt , bal_updates ) ( src , am ) -> Token . transfer ctxt src ` Burned am >>=? fun ( ctxt , debit_logs ) -> return ( ctxt , bal_updates @ de... |
let test_transfer_n_with_empty_source ( ) = Random . init 0 ; create_context ( ) >>=? fun ( ctxt , pkh ) -> wrap ( test_transfer_n ctxt [ ] ` Block_fees ) >>=? fun _ -> let dest = ` Delegate_balance pkh in wrap ( test_transfer_n ctxt [ ] dest ) |
let test_transfer_n_with_non_empty_source ( ) = Random . init 0 ; create_context ( ) >>=? fun ( ctxt , pkh ) -> let origin = ` Contract ( Contract . implicit_contract pkh ) in let ( user1 , _ , _ ) = Signature . generate_key ( ) in let user1c = ` Contract ( Contract ... |
let tests = Tztest . [ tztest " transfer - balances " ` Quick test_simple_balances ; tztest " transfer - balance updates " ` Quick test_simple_balance_updates ; tztest " transfer - test allocated " ` Quick test_allocated ; tztest " transfer - test transfer to sink " ` Quick test_t... |
module Yaml = struct type t = | Scalar of string | List of t list | Record of ( string * t ) list let scalar str = Scalar str let list lst = List lst let record lst = Record lst module Pretty = Fmlib_pretty . Print let rec to_doc : t -> Pretty . doc = function | Scalar str -> Pretty . text str ... |
module Token = struct type t = | String of string | Colon | Dash let string str = String str let to_string : t -> string = function | String str -> " " < ^ str ^ " " > | Colon -> " ' ' " : | Dash -> " ' ' " - end |
module Token_plus = struct type t = Position . range * Token . t end |
module Lexer = struct module CP = Character . Make ( Unit ) ( Token_plus ) ( Fmlib_std . Void ) open CP let comment : char t = let * _ = char ' ' # in let * _ = ( charp ( fun c -> c <> ' \ n ' ) " comment character " ) |> skip_zero_or_more in return ' ' # let whit... |
module Combinator = struct module TP = Token_parser . Make ( Unit ) ( Token ) ( Yaml ) ( Fmlib_std . Void ) module Parser = TP . Parser open TP let string : string t = step " string " ( fun _ _ tok -> match tok with | Token . String str -> Some ( str , ( ) ) | _ -> N... |
module PL = struct include Parse_with_lexer . Make ( Unit ) ( Token ) ( Yaml ) ( Void ) ( Lex ) ( Parse ) let start : t = make Lex . init Combinator . parse end |
let write_error ( str : string ) ( p : PL . t ) : unit = let module Reporter = Error_reporter . Make ( PL ) in Reporter . ( make_syntax p |> run_on_string str |> Pretty . layout 50 |> Pretty . write_to_channel stdout ) let open PL in let str = { | names : - Alice - " Bob " ... |
let test ( ? check = true ) iter n edges = let v = Array . init n V . create in let g = create ( ) in let ( ) = Array . iter ( add_vertex g ) v in let build ( s , t ) = add_edge g v . ( s ) v . ( t ) in List . iter build edges ; let num = Array . make n 0 in let i ... |
let tests iter = let test = test iter in test 3 [ 0 , 1 ; 1 , 2 ] ; test 3 [ ] ; test 1 [ 0 , 0 ] ; test 2 [ 0 , 1 ; 1 , 0 ] ; test 3 [ 0 , 1 ; 1 , 0 ; 1 , 2 ] ; test 3 [ 2 , 0 ; 0 , 2 ; 0 , 1 ] ; test 3 [ 1 , 2 ;... |
let ( ) = tests Topological . iter |
let rec pow a = function | 0 -> 1 | 1 -> a | n -> let b = pow a ( n / 2 ) in b * b * ( if n mod 2 = 0 then 1 else a ) |
let ( ) = for n_iter = 0 to 5 do let n = pow 10 n_iter in let el = ref [ ] in el := [ n - 1 , 0 ] ; for i = 0 to n - 2 do el := ( i , i + 1 ) :: ! el done ; test ~ check : false Topological . iter n ! el done |
let transfer_to_itself_and_check_balances ~ loc b ( ? fee = Tez . zero ) contract amount = Context . Contract . balance ( I b ) contract >>=? fun bal -> Op . transaction ( I b ) ~ fee contract contract amount >>=? fun op -> Incremental . add_operation b op >>=? fun b -> Assert . balan... |
let ten_tez = of_int 10 |
let two_over_n_of_balance incr contract n = Context . Contract . balance ( I incr ) contract >>=? fun balance -> Lwt . return ( balance /? n >>? fun res -> res *? 2L ) |
let single_transfer ? fee ? expect_failure amount = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> transfer_and_check_balances ~ loc : __LOC__ ? fee ? expect_failure b contract_1 contract_2 amount >>=? fun ( b , _ ) -... |
let test_block_with_a_single_transfer ( ) = single_transfer Tez . one |
let test_block_with_a_single_transfer_with_fee ( ) = single_transfer ~ fee : Tez . one Tez . one |
let test_transfer_zero_tez ( ) = single_transfer ~ expect_failure ( : function | Environment . Ecoproto_error ( Apply . Empty_transaction _ as e ) :: _ -> Assert . test_error_encodings e ; return_unit | _ -> failwith " Empty transaction should fail " ) Tez . zero |
let test_transfer_zero_implicit ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let dest = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account = Account . new_account ( ) in Incremental . begin_construction b >>=? fun i -> let src = Contrac... |
let test_transfer_to_originate_with_fee ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in Incremental . begin_construction b >>=? fun b -> two_over_n_of_balance b contract 10L >>=? fun fee -> ... |
let test_transfer_amount_of_contract_balance ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Context . Contract . pkh contract_1 >>=? fun pkh1 -> Incremental . begin_construction b ~ policy ( : Block . Excluding [ pkh1 ] ) >>=? fun b -> Context . Contra... |
let test_transfers_to_self ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in Incremental . begin_construction b >>=? fun b -> two_over_n_of_balance b contract 3L >>=? fun amount -> transfer_to... |
let test_missing_transaction ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Context . Contract . pkh contract_1 >>=? fun pkh1 -> Incremental . begin_construction b ~ policy ( : Block . Excluding [ pkh1 ] ) >>=? fun b -> two_over_n_of_balance b contract_1... |
let test_transfer_zero_implicit_with_bal_src_as_fee ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let dest = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account = Account . new_account ( ) in Incremental . begin_construction b >>=? fun i -... |
let test_transfer_zero_to_originated_with_bal_src_as_fee ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let dest = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account = Account . new_account ( ) in Incremental . begin_construction b >>=? fun... |
let test_transfer_one_to_implicit_with_bal_src_as_fee ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let dest = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account = Account . new_account ( ) in Incremental . begin_construction b >>=? fun i ... |
let test_transfer_from_implicit_to_implicit_contract ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let bootstrap_contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account_a = Account . new_account ( ) in let account_b = Account . new_a... |
let test_transfer_from_implicit_to_originated_contract ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let bootstrap_contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let contract = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nt... |
let multiple_transfer n ? fee amount = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> n_transactions n b ? fee contract_1 contract_2 amount >>=? fun b -> Incremental . finalize_block b >>=? fun _ -> return_unit |
let test_block_with_multiple_transfers ( ) = multiple_transfer 99 ( of_int 1000 ) |
let test_block_with_multiple_transfers_pay_fee ( ) = multiple_transfer 10 ~ fee : ten_tez ( of_int 1000 ) |
let test_block_with_multiple_transfers_with_without_fee ( ) = Context . init 8 >>=? fun ( b , contracts ) -> let contracts = Array . of_list contracts in Incremental . begin_construction b >>=? fun b -> let hundred = of_int 100 in let ten = of_int 10 in let twenty = of_int 20 in n_transacti... |
let test_build_a_chain ( ) = Context . init2 ~ consensus_threshold : 0 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> let ten = of_int 10 in List . fold_left_es ( fun b _ -> Incremental . begin_construction b >>=? fun b -> transfer_and_check_balances ~ loc : __LOC__ b contract_1 ... |
let test_empty_implicit ( ) = Context . init 1 >>=? fun ( b , contracts ) -> let dest = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let account = Account . new_account ( ) in Incremental . begin_construction b >>=? fun incr -> let src = Contract . ... |
let test_balance_too_low fee ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun i -> Context . Contract . balance ( I i ) contract_1 >>=? fun balance1 -> Context . Contract . balance ( I i ) contract_2 >>=? fun ba... |
let test_balance_too_low_two_transfers fee ( ) = Context . init 3 >>=? fun ( b , contracts ) -> let contract_1 = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 0 in let contract_2 = WithExceptions . Option . get ~ loc : __LOC__ @@ List . nth contracts 1 in ... |
let invalid_counter ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> Op . transaction ( I b ) contract_1 contract_2 Tez . one >>=? fun op1 -> Op . transaction ( I b ) contract_1 contract_2 Tez . one >>=? fu... |
let test_add_the_same_operation_twice ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> transfer_and_check_balances ~ loc : __LOC__ b contract_1 contract_2 ten_tez >>=? fun ( b , op_transfer ) -> Op . transaction ... |
let invalid_counter_in_the_future ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> Context . Contract . counter ( I b ) contract_1 >>=? fun cpt -> let counter = Z . add cpt ( Z . of_int 10 ) in Op . tran... |
let test_ownership_sender ( ) = Context . init2 ( ) >>=? fun ( b , contract_1 , contract_2 ) -> Incremental . begin_construction b >>=? fun b -> Context . Contract . manager ( I b ) contract_1 >>=? fun manager -> let imcontract_1 = Alpha_context . Contract . implicit_contract man... |
let random_range ( min , max ) = let interv = max - min + 1 in let init = Random . self_init ( ) ; Random . int interv + min in init |
let random_contract contract_array = let i = Random . int ( Array . length contract_array ) in contract_array . ( i ) |
let test_random_transfer ( ) = Context . init 10 >>=? fun ( b , contracts ) -> let contracts = Array . of_list contracts in let source = random_contract contracts in let dest = random_contract contracts in Context . Contract . pkh source >>=? fun source_pkh -> Incremental . begin_constructi... |
let test_random_multi_transactions ( ) = let n = random_range ( 1 , 100 ) in multiple_transfer n ( of_int 100 ) |
let test_bad_entrypoint ( ) = Context . init 1 >>=? fun ( b , _cs ) -> Incremental . begin_construction b >>=? fun v -> let ctxt = Incremental . alpha_ctxt v in let storage = " Unit " in let parameter = " Unit " in let entrypoint = Entrypoint . of_string_strict_exn " bad entrypoin... |
let test_bad_parameter ( ) = Context . init 1 >>=? fun ( b , _cs ) -> Incremental . begin_construction b >>=? fun v -> let ctxt = Incremental . alpha_ctxt v in let storage = " Unit " in let parameter = " 1 " in Contract_helpers . run_script ctxt " { parameter unit ; storage un... |
let transfer_to_itself_with_no_such_entrypoint ( ) = let entrypoint = Entrypoint . of_string_strict_exn " bad entrypoint " in Context . init 1 >>=? fun ( b , contract ) -> Incremental . begin_construction b >>=? fun i -> let addr = match contract with [ hd ] -> hd | _ -> assert false... |
let tests = [ Tztest . tztest " single transfer " ` Quick test_block_with_a_single_transfer ; Tztest . tztest " single transfer with fee " ` Quick test_block_with_a_single_transfer_with_fee ; Tztest . tztest " single transfer zero tez " ` Quick test_transfer_zero_tez ; Tztest . tztest... |
let test_parse_and_format kind_name ~ fg test_name ~ input ~ expected = let test_name = Stdlib . Format . sprintf " parse_and_format % s : % s " kind_name test_name in ( test_name , ` Quick , fun ( ) -> let actual = Translation_unit . parse_and_format fg ~ input_name " :< test " >... |
let test_parse_and_format_signature = let make_test = test_parse_and_format " signature " ~ fg : Signature in [ make_test " val " ~ input " : val x :\ n \ nint " ~ expected ( : Ok " val x : int \ n " ) ] |
let test_parse_and_format_use_file = let make_test = test_parse_and_format " use_file " ~ fg : Use_file in [ make_test " let " ~ input " : let x =\ n \ n y " ~ expected ( : Ok " let x = y \ n " ) ] |
let test_parse_and_format_core_type = let make_test = test_parse_and_format " core_type " ~ fg : Core_type in [ make_test " string " ~ input " : string " ~ expected ( : Ok " string \ n " ) ; make_test " int " ~ input " : int " ~ expected ( : Ok " int \ n " ) ; mak... |
let test_parse_and_format_module_type = let make_test = test_parse_and_format " module_type " ~ fg : Module_type in [ make_test " sig end " ~ input " : sig end " ~ expected ( : Ok " sig end \ n " ) ; make_test " sig end 2 " ~ input : " sig \ n \ n \ \ val x : foo -> bar ... |
let test_parse_and_format_expression = let make_test = test_parse_and_format " expression " ~ fg : Expression in [ make_test " List . map " ~ input " : List . map ( fun x ->\ nx * x ) [ ( 1 + 9 ) ; 2 ; 3 ] " ~ expected ( : Ok " List . map ( fun x -> x * x ) [... |
let reindent ~ source ~ range indents = let low , high = Range . get range in let lines = String . split_lines source in let low = low - 1 and high = high - 1 in String . concat ~ sep " :\ n " @@ List . mapi lines ~ f ( : fun i line -> if i < low then line else if low <= i && i <= h... |
let test_numeric = let make_test name ~ source ~ range expected = let test_name = " numeric : " ^ name in ( test_name , ` Quick , fun ( ) -> let range = Range . make ~ range source in let got = Translation_unit . numeric Use_file ~ input_name " : _ " ~ source ~ range Conf . def... |
let foooooooooooo = let foooooooooooooo = |
let woooooooooooooooo = koooooooooooooooo in baaaaaar in hooohoooo } | ~ range ( : 1 , 7 ) { | let foooooooooooo = let foooooooo = foooooooooooo in foooooooooooo |
let foooooooooooo = let foooooooooooooo = let woooooooooooooooo = koooooooooooooooo in baaaaaar in hooohoooo } | ; make_test " with parens and begin / end " ~ source : { | let x = begin let y = ( if ( k = x ) then begin match k , v with [ x ; y ] -> ( foo ; ( if ( z ) then ... |
let foooooooooooo = ( [ foooooo } | ~ range ( : 1 , 6 ) { | let foooooo = let foooooooooooo = ( [ fun x -> foooooo } | ; make_test " already formatted function " ~ source : { | let fmt_expressions c width sub_exp exprs fmt_expr ( p : Params . elements_collection ) = mat... |
let x = 3 in x + y } | { | |
let x = 3 in |
let read_file f = Stdio . In_channel . with_file f ~ f : Stdio . In_channel . input_all |
let test_numeric_file = let _fmt_ast_source = read_file " . . . . // lib / Fmt_ast . ml " in let partial_source = read_file " . . / passing / tests / partial . ml " in let inv_with_loc_source = read_file " . . / passing / tests / format_invalid_files_with_locations . ml " ... |
let tests = List . concat [ test_parse_and_format_signature @ test_parse_and_format_use_file @ test_parse_and_format_core_type @ test_parse_and_format_module_type @ test_parse_and_format_expression @ test_numeric @ test_numeric_file ] |
module T = Transport object val mutable _opened = true val mutable _current_idx_input = 0 inherit Transport . t method isOpen = _opened method opn = ( ) method close = _opened <- false method read buf off len = let input_buf_length = Buffer . length i in if len + _current_idx_input > input_buf_... |
let medium_list x = QCheck . ( list_of_size ( Gen . int_bound 100 ) x ) |
let list_values_are_unique l = List . length ( List . sort_uniq compare l ) = List . length l |
let assume_unique_keys ( type a ) : ( char list * a ) list -> unit = fun kv_list -> let keys = List . map fst kv_list in QCheck . assume ( list_values_are_unique keys ) |
let make_tests m = let module Char_trie = ( val m : Trie . S with type key = char list ) in let trie_of_key_value_list ( type a ) : ( Char_trie . key * a ) list -> a Char_trie . t = fun l -> List . fold_left ( fun acc ( key , value ) -> Char_trie . add key value acc ) Char_trie... |
let ( ) = let tests = [ ( module Char_trie : Trie . S with type key = char list ) ; ( module Array_char_trie : Trie . S with type key = char list ) ] |> List . map make_tests |> List . concat in QCheck_runner . run_tests_main tests |
let fmt_list to_string l = sprintf " [ % s ] " ( l |> List . map to_string |> String . concat " " ) |
let fmt_graph l = sprintf " [ % s ] " ( l |> List . map ( fun ( v , vl ) -> sprintf " % i ->% s " v ( fmt_list string_of_int vl ) ) |> String . concat " " ) |
let fmt_partition l = fmt_list ( fmt_list string_of_int ) l |
let fmt_tsort_result res = match res with | Tsort . Sorted l -> sprintf " Sorted % s " ( fmt_list string_of_int l ) | Tsort . ErrorCycle l -> sprintf " ErrorCycle % s " ( fmt_list string_of_int l ) |
let test_find_nonexistent_nodes ( ) = assert ( ( Tsort . find_nonexistent_nodes [ 1 , [ ] ; 2 , [ 3 ] ] ) = [ 2 , [ 3 ] ] ) ; assert ( ( Tsort . find_nonexistent_nodes [ 1 , [ ] ; 2 , [ 3 ] ; 4 , [ 5 ; 6 ; 7 ; 5 ] ; 6 , ... |
let test_tsort ( ) = let sort graph = printf " input : % s \ n " %! ( fmt_graph graph ) ; let res = Tsort . sort graph in printf " output : % s \ n " %! ( fmt_tsort_result res ) ; res in assert ( sort [ ] = Sorted [ ] ) ; assert ( sort [ 1 , [ 2 ] ; 2 ,... |
let test_find_sc_components ( ) = let p graph = printf " input : % s \ n " %! ( fmt_graph graph ) ; let partition = Tsort . find_strongly_connected_components graph in printf " output : % s \ n " %! ( fmt_partition partition ) ; partition in assert ( p [ ] = [ ] ) ; a... |
let test_sort_sc_components ( ) = let sort graph = printf " input : % s \ n " %! ( fmt_graph graph ) ; let components = Tsort . sort_strongly_connected_components graph in printf " output : % s \ n " %! ( fmt_partition components ) ; components in assert ( sort [ ] = [ ] ... |
let main ( ) = Alcotest . run " Tsort " [ " Tsort " , [ " find nonexistent nodes " , ` Quick , test_find_nonexistent_nodes ; " sort " , ` Quick , test_tsort ; " find s . c . components " , ` Quick , test_find_sc_components ; " sort s . c . components " ... |
let ( ) = main ( ) |
type a = char [ @ gen QCheck . Gen . pure ' a ' ] ' a ' |
type b = char [ @ gen QCheck . Gen . pure ' b ' ] ' b ' |
type c = char [ @ gen QCheck . Gen . pure ' c ' ] ' c ' |
type d = char [ @ gen QCheck . Gen . pure ' d ' ] ' d ' |
type e = char [ @ gen QCheck . Gen . pure ' e ' ] ' e ' |
type f = char [ @ gen QCheck . Gen . pure ' f ' ] ' f ' |
type g = char [ @ gen QCheck . Gen . pure ' g ' ] ' g ' |
type h = char [ @ gen QCheck . Gen . pure ' h ' ] ' h ' |
type i = char [ @ gen QCheck . Gen . pure ' i ' ] ' i ' |
type tup2 = a * b |
type tup3 = a * b * c |
type tup4 = a * b * c * d |
type tup5 = a * b * c * d * e |
type tup6 = a * b * c * d * e * f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.