text
stringlengths
0
601k
let tickets_of_value ctxt ~ include_lazy ~ type_exp ~ value_exp = let ( Script_ir_translator . Ex_ty ty , ctxt ) = let node = Micheline . root @@ Expr . from_string type_exp in Result . value_f ~ default ( : fun ( ) -> Stdlib . failwith " Failed to parse " ) ( Script_ir_translator . parse_any_ty ctxt ~ legacy : false n...
let assert_contains_tickets ctxt ~ loc ~ include_lazy ~ type_exp ~ value_exp expected = let * ( ex_tickets , _ ) = tickets_of_value ctxt ~ include_lazy ~ type_exp ~ value_exp in assert_equals_ex_tickets ctxt ~ loc ex_tickets expected
let assert_fail_non_empty_overlay ctxt ~ loc ~ include_lazy ~ type_exp ~ value_exp = tickets_of_value ctxt ~ include_lazy ~ type_exp ~ value_exp >>= fun res -> match res with | Error [ x ] -> let x = Format . kasprintf Fun . id " % a " Error_monad . pp x in Assert . equal ~ loc String . equal " " Format . pp_print_stri...
let make_string_tickets ctxt ticketer_amounts = List . fold_right_es ( fun ( ticketer , content , amount ) ( tickets , ctxt ) -> let * ( ticket , ctxt ) = make_ex_ticket ctxt ~ ticketer ~ type_exp " : string " ~ content_exp ( : Printf . sprintf { " |% s " } | content ) ~ amount in return ( ticket :: tickets , ctxt ) ) ...
let tickets_from_big_map_ref ~ pre_populated value_exp = let * ( block , contracts ) = Context . init 1 in let source = WithExceptions . Option . get ~ loc : __LOC__ @@ List . hd contracts in let * ( operation , originated ) = Op . contract_origination ( B block ) source ~ script : Op . dummy_script in let * block = Bl...
let assert_big_map_int_ticket_string_ref ~ loc ~ pre_populated ~ big_map_exp ex_tickets = let * ( value_exp , ctxt ) = tickets_from_big_map_ref ~ pre_populated big_map_exp in let * ( ex_tickets , ctxt ) = make_string_tickets ctxt ex_tickets in assert_contains_tickets ctxt ~ include_lazy : true ~ loc ~ type_exp " : big_...
let assert_fail_non_empty_overlay_with_big_map_ref ~ loc ~ pre_populated ~ big_map_exp = let * ( value_exp , ctxt ) = tickets_from_big_map_ref ~ pre_populated big_map_exp in assert_fail_non_empty_overlay ctxt ~ include_lazy : true ~ loc ~ type_exp " : big_map int ( ticket string ) " ~ value_exp
let test_tickets_in_unit_ticket ( ) = let * ctxt = new_ctxt ( ) in let type_exp = " ticket ( unit ) " in let value_exp = { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " Unit 10 } | in let * ( ex_ticket , ctxt ) = make_ex_ticket ctxt ~ ticketer " : KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " ~ type_exp " : unit " ~ content...
let assert_string_tickets ~ loc ~ include_lazy ~ type_exp ~ value_exp ~ expected = let * ctxt = new_ctxt ( ) in let * ( ex_tickets , ctxt ) = make_string_tickets ctxt expected in assert_contains_tickets ctxt ~ include_lazy ~ loc ~ type_exp ~ value_exp ex_tickets
let test_tickets_in_list ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : list ( ticket ( string ) ) " ~ value_exp : { | { Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ; Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 2 ; Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " ...
let test_tickets_in_pair ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : pair ( ticket string ) ( ticket string ) " ~ value_exp : { | Pair ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 2 ) } | ~ expected : [ ( " KT...
let test_tickets_in_map ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : map int ( ticket string ) " ~ value_exp : { | { Elt 1 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ; Elt 2 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 2 ) ; } } | ~ expected : [ ( " KT1...
let test_tickets_in_big_map ( ) = let * ctxt = new_ctxt ( ) in assert_fail_non_empty_overlay ctxt ~ loc : __LOC__ ~ include_lazy : true ~ type_exp " : big_map int ( ticket string ) " ~ value_exp : { | { Elt 1 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ; Elt 2 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeH...
let test_tickets_in_big_map_strict_only ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : big_map int ( ticket string ) " ~ value_exp : { | { Elt 1 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ; Elt 2 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 2 ) ; } } | ~ ...
let test_tickets_in_list_in_big_map ( ) = let * ctxt = new_ctxt ( ) in assert_fail_non_empty_overlay ctxt ~ loc : __LOC__ ~ include_lazy : true ~ type_exp " ( : big_map int ( list ( ticket string ) ) ) " ~ value_exp : { | { Elt 1 { Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ; Pair " KT1ThEdxfUcWUwqsdergy3Q...
let test_tickets_in_pair_big_map_and_list_strict_only ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : pair ( big_map int ( ticket string ) ) ( list ( ticket string ) ) " ~ value_exp : { | Pair { Elt 1 ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ; Elt 2 ( Pair " KT1ThEdx...
let test_tickets_in_or_left ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : or ( ticket string ) int " ~ value_exp { :| Left ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) } | ~ expected [ ( " : KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " , " red " , 1 ) ]
let test_tickets_in_or_right ( ) = assert_string_tickets ~ loc : __LOC__ ~ include_lazy : false ~ type_exp " : or int ( ticket string ) " ~ value_exp { :| Right ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) } | ~ expected [ ( " : KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " , " red " , 1 ) ]
let test_tickets_in_empty_big_map_ref ( ) = assert_big_map_int_ticket_string_ref ~ loc : __LOC__ ~ pre_populated [ ] : ~ big_map_exp ( : Printf . sprintf " % s " ) [ ]
let test_tickets_in_non_empty_big_map_ref ( ) = assert_big_map_int_ticket_string_ref ~ loc : __LOC__ ~ pre_populated : [ ( 1 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 } ) ; | ( 2 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 1 } ) ; | ( 3 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUH...
let test_tickets_overlay_in_empty_big_map_ref ( ) = assert_fail_non_empty_overlay_with_big_map_ref ~ loc : __LOC__ ~ pre_populated [ ] : ~ big_map_exp : ( Printf . sprintf { | Pair % s { Elt 1 ( Some ( Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 ) ) } } ) |
let test_tickets_overlay_in_non_empty_in_big_map_ref ( ) = assert_fail_non_empty_overlay_with_big_map_ref ~ loc : __LOC__ ~ pre_populated : [ ( 1 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 } ) ; | ( 2 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " green " 1 } ) ; | ( 3 , { | Pair " KT1ThEdxfUc...
let test_tickets_replace_overlay_in_non_empty_in_big_map_ref ( ) = assert_fail_non_empty_overlay_with_big_map_ref ~ loc : __LOC__ ~ pre_populated : [ ( 1 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 } ) ] | ~ big_map_exp : ( Printf . sprintf { | Pair % s { Elt 1 ( Some ( Pair " KT1ThEdxfUcWUwqsdergy3Qn...
let test_tickets_remove_overlay_in_non_empty_in_big_map_ref ( ) = assert_fail_non_empty_overlay_with_big_map_ref ~ loc : __LOC__ ~ pre_populated : [ ( 1 , { | Pair " KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " " red " 1 } ) ] | ~ big_map_exp ( : Printf . sprintf { | Pair % s { Elt 1 None } } ) |
let tests = [ Tztest . tztest " Test tickets in unit ticket " ` Quick test_tickets_in_unit_ticket ; Tztest . tztest " Test tickets in list " ` Quick test_tickets_in_list ; Tztest . tztest " Test tickets in pair " ` Quick test_tickets_in_pair ; Tztest . tztest " Test tickets in map " ` Quick test_tickets_in_map ; Tztest...
let ( let * ) m f = m >>=? f
let wrap m = m >|= Environment . wrap_tzresult
let make_context ( ) = let * ( block , _ ) = Context . init 1 in let * incr = Incremental . begin_construction block in return ( Incremental . alpha_ctxt incr )
let hash_key ctxt ~ ticketer ~ typ ~ contents ~ owner = let ticketer = Micheline . root @@ Expr . from_string ticketer in let typ = Micheline . root @@ Expr . from_string typ in let contents = Micheline . root @@ Expr . from_string contents in let owner = Micheline . root @@ Expr . from_string owner in wrap @@ Lwt . re...
let assert_balance ctxt ~ loc key expected = let * ( balance , _ ) = wrap @@ Ticket_balance . get_balance ctxt key in match balance with | Some b -> Assert . equal_int ~ loc ( Z . to_int b ) expected | None -> failwith " Expected balance % d " expected
let assert_no_balance ctxt key = let * ( balance , _ ) = wrap @@ Ticket_balance . get_balance ctxt key in match balance with | Some b -> failwith " Expected empty ( none ) balance but got % d " ( Z . to_int b ) | None -> return ( )
let adjust_balance ctxt key delta = wrap @@ Ticket_balance . adjust_balance ctxt key ~ delta ( : Z . of_int delta )
let assert_non_overlapping_keys ~ loc ~ ticketer1 ~ ticketer2 ~ contents1 ~ contents2 ~ typ1 ~ typ2 ~ owner1 ~ owner2 = let * ctxt = make_context ( ) in let * ( k1 , ctxt ) = hash_key ctxt ~ ticketer : ticketer1 ~ typ : typ1 ~ contents : contents1 ~ owner : owner1 in let * ( k2 , _ctxt ) = hash_key ctxt ~ ticketer : ti...
let make_key ctxt content = hash_key ctxt ~ ticketer { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ typ " : string " ~ contents ( : Printf . sprintf { " |% s " } | content ) ~ owner { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } |
let test_non_overlapping_keys_ticketer ( ) = assert_non_overlapping_keys ~ loc : __LOC__ ~ ticketer1 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ ticketer2 { " :| KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn " } | ~ typ1 " : nat " ~ typ2 " : int " ~ contents1 { " :| 1 " } | ~ contents2 { " :| 1 " } | ~ owner1 { " :| KT1...
let test_non_overlapping_keys_contents ( ) = assert_non_overlapping_keys ~ loc : __LOC__ ~ ticketer1 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ ticketer2 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ typ1 " : string " ~ typ2 " : string " ~ contents1 { " :| red " } | ~ contents2 { " :| blue " } | ~ owner1...
let test_non_overlapping_keys_type ( ) = assert_non_overlapping_keys ~ loc : __LOC__ ~ ticketer1 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ ticketer2 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ typ1 " : nat " ~ typ2 " : int " ~ contents1 { " :| 1 " } | ~ contents2 { " :| 1 " } | ~ owner1 { " :| KT1ThEd...
let test_non_overlapping_keys_owner ( ) = assert_non_overlapping_keys ~ loc : __LOC__ ~ ticketer1 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ ticketer2 { " :| KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq " } | ~ typ1 " : nat " ~ typ2 " : int " ~ contents1 { " :| 1 " } | ~ contents2 { " :| 1 " } | ~ owner1 { " :| KT1ThE...
let test_ticket_balance_single_update ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in let * ( _ , ctxt ) = adjust_balance ctxt alice_red 1 in assert_balance ctxt ~ loc : __LOC__ alice_red 1
let test_ticket_balance_different_owners ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in let * ( alice_blue , ctxt ) = make_key ctxt " alice_blue " in let * ( _ , ctxt ) = adjust_balance ctxt alice_red 1 in let * ( _ , ctxt ) = adjust_balance ctxt alice_blue 1 in let *...
let test_ticket_balance_multiple_updates ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in let * ( _ , ctxt ) = adjust_balance ctxt alice_red 1 in let * ( _ , ctxt ) = adjust_balance ctxt alice_red 2 in let * ( _ , ctxt ) = adjust_balance ctxt alice_red ( - 1 ) in assert...
let test_empty_balance ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in assert_no_balance ctxt alice_red
let test_empty_balance_after_update ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in let * ( _ , ctxt ) = adjust_balance ctxt alice_red 1 in let * ( _ , ctxt ) = adjust_balance ctxt alice_red ( - 1 ) in assert_no_balance ctxt alice_red
let test_negative_balance ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in adjust_balance ctxt alice_red ( - 1 ) >>= fun res -> Assert . proto_error ~ loc : __LOC__ res ( fun _err -> true )
let test_storage_space ( ) = let * ctxt = make_context ( ) in let * ( alice_red , ctxt ) = make_key ctxt " alice_red " in let * ( space , ctxt ) = adjust_balance ctxt alice_red 1 in let * ( ) = Assert . equal_int ~ loc : __LOC__ 66 ( Z . to_int space ) in let * ( space , ctxt ) = adjust_balance ctxt alice_red 1 in let ...
let tests = [ Tztest . tztest " no overlapping keys for ticketer " ` Quick test_non_overlapping_keys_ticketer ; Tztest . tztest " no overlapping keys for content " ` Quick test_non_overlapping_keys_contents ; Tztest . tztest " no overlapping keys for content type " ` Quick test_non_overlapping_keys_type ; Tztest . tzte...
let create ( ) = let open Uint16 in Tile_data . create ~ start_addr ( : of_int 0x8000 ) ~ end_addr ( : of_int 0x97FF ) let open Uint16 in let t = create ( ) in t |> Tile_data . write_byte ~ addr ( : of_int 0x8000 ) ~ data ( : Uint8 . of_int 0b01001110 ) ; t |> Tile_data . write_byte ~ addr ( : of_int 0x8001 ) ~ data ( ...
let area0_start_addr = Uint16 . of_int 0x9800
let area1_start_addr = Uint16 . of_int 0x9C00
let create ( ) = Tile_map . create ~ area0_start_addr ~ area0_end_addr ( : Uint16 . of_int 0x9BFF ) ~ area1_start_addr ~ area1_end_addr ( : Uint16 . of_int 0x9FFF )
let print_all_tiles ~ area t = for y = 0 to 30 do for x = 0 to 60 do Tile_map . get_tile_index t ~ area ~ y ~ x |> Uint8 . to_int |> Printf . printf " % d " done ; Printf . printf " \ n " done
let write t ~ area ~ y ~ x ~ data = let start = match area with Tile_map . Area0 -> area0_start_addr | Area1 -> area1_start_addr in Tile_map . write_byte t ~ addr : Uint16 . ( start + of_int y * of_int 32 + of_int x ) ~ data : Uint8 . ( of_int data ) let t = create ( ) in Tile_map . write_byte t ~ addr : area0_start_ad...
module Protocol = struct include Protocol open QCheck2 let max_rfc3339_seconds = to_seconds max_rfc3339 let min_rfc3339_seconds = to_seconds min_rfc3339 let gen = Gen . ( map of_seconds int64 ) let rfc3339_compatible_t_gen = let open Gen in let within_rfc3339 = map of_seconds ( int64_range_gen min_rfc3339_seconds max_r...
module System = struct open System open QCheck2 let gen_date : ( int * int * int ) Gen . t = let open Gen in let thirty_one = [ 1 ; 3 ; 5 ; 7 ; 8 ; 10 ; 12 ] |> List . map pure |> oneof in let thirty = [ 4 ; 6 ; 9 ; 11 ] |> List . map pure |> oneof in let gen_month_day = oneof [ pair thirty_one ( 1 -- 31 ) ; pair thirt...
let ( ) = Alcotest . run " Time " [ ( " Protocol " , qcheck_wrap Protocol . tests ) ; ( " System " , qcheck_wrap System . tests ) ; ]
let wrap e = Lwt . return ( Environment . wrap_tzresult e )
let simple_test ( ) = let ( public , secret ) = Timelock . gen_rsa_keys ( ) in let locked_value = Timelock . gen_locked_value public in let time = 1000 in let unlocked_value = Timelock . unlock_with_secret secret ~ time locked_value in let ( same_unlocked , proof ) = Timelock . unlock_and_prove_without_secret public ~ ...
let contract_test ( ) = let originate_contract file storage src b = let load_file f = let ic = open_in f in let res = really_input_string ic ( in_channel_length ic ) in close_in ic ; res in let contract_string = load_file file in let code = Expr . toplevel_from_string contract_string in let storage = Expr . from_string...
let tests = [ Tztest . tztest " simple test " ` Quick simple_test ; Tztest . tztest " contract test " ` Quick contract_test ; ]
let div_addr = Uint16 . ( of_int 0xFF04 )
let tima_addr = Uint16 . ( of_int 0xFF05 )
let tma_addr = Uint16 . ( of_int 0xFF06 )
let tac_addr = Uint16 . ( of_int 0xFF07 )
let ic = Interrupt_controller . create ~ ie_addr : Uint16 . ( of_int 0xFFFF ) ~ if_addr : Uint16 . ( of_int 0xFF0F )
let create ( ) = Timer . create ~ div_addr ~ tima_addr ~ tma_addr ~ tac_addr ~ ic
let set_tima t bits = Timer . write_byte t ~ addr : tac_addr ~ data : Uint8 . ( of_int bits )
let print t addr = Timer . read_byte t addr |> Uint8 . show |> print_endline
let print_before_and_after_mcycles t addr mcycles = Timer . run t ~ mcycles ( : mcycles - 1 ) ; print t addr ; Timer . run t ~ mcycles : 1 ; print t addr let t = create ( ) in print_before_and_after_mcycles t div_addr 64 ; [ % expect { | $ 00 $ 01 } ] | let t = create ( ) in print_before_and_after_mcycles t div_addr ( ...
type time_ns = Time_ns . t [ @@ deriving compare ]
let quickcheck_generator = let open Quickcheck . Generator . Let_syntax in let % map ns_since_epoch = Int63 . gen_incl ( Time_ns . to_int63_ns_since_epoch Time_ns . min_value_for_1us_rounding ) ( Time_ns . to_int63_ns_since_epoch Time_ns . max_value_for_1us_rounding ) in Time_ns . of_int63_ns_since_epoch ns_since_epoch...
let randomly_round quickcheck_generator = let open Quickcheck . Generator . Let_syntax in let % bind time_ns = quickcheck_generator in let % map unit = Quickcheck . Generator . of_list [ Time_ns . Span . second ; Time_ns . Span . of_int_ms 100 ; Time_ns . Span . of_int_ms 10 ; Time_ns . Span . millisecond ; Time_ns . S...
let quickcheck here quickcheck_generator f = require_does_not_raise here ( fun ( ) -> Quickcheck . test quickcheck_generator ~ f ~ sexp_of [ :% sexp_of : time_ns ] ~ examples : [ Time_ns . min_value_for_1us_rounding ; Time_ns . epoch ; Time_ns . max_value_for_1us_rounding ] ) ; ; ( module struct module Span = Time_ns ....
let succ time_ns = time_ns |> Time_ns . to_int63_ns_since_epoch |> Int63 . succ |> Time_ns . of_int63_ns_since_epoch ; ;
let pred time_ns = time_ns |> Time_ns . to_int63_ns_since_epoch |> Int63 . pred |> Time_ns . of_int63_ns_since_epoch ; ; print_and_check_stable_type [ % here ] ( module Time_ns . Stable . Alternate_sexp . V1 ) [ Time_ns . min_value_for_1us_rounding ; Time_ns . min_value_for_1us_rounding |> succ ; Time_ns . min_value_fo...
module Span = struct open ! Time_ns . Span let % test ( _ [ @ tags " 64 - bits - only " ] ) = Int . ( > ) ( to_int_sec ( of_int63_ns Int63 . max_value ) ) 0 ; ; let % test_module " overflow silently " = ( module struct let doesn ' t_raise = Fn . non Exn . does_raise let % test " + range up " = doesn ' t_raise ( fun ( )...
[ %% import " config . h " ] ( module struct [ %% ifdef JSC_ARCH_SIXTYFOUR ] let % expect_test " time moves backwards " = let y2000 = Time . of_string " 2000 - 01 - 01 00 : 00 : 00 UTC " |> Time . to_span_since_epoch |> Time . Span . to_sec in let one_hour = 3600 . in let half_a_year = 3600 . . * 24 . . * 30 . . * 6 . ...
module Examples = struct let % expect_test " sample transitions " = let zone = Time . Zone . find_exn " America / New_York " in let time = Time . of_date_ofday ~ zone ( Date . of_string " 2013 - 10 - 07 " ) ( Time . Ofday . of_string " 09 : 30 " ) in let prev_clock_shift = Time . Zone . prev_clock_shift zone ~ at_or_be...
module type Time = sig module Zone : sig type t val find_exn : string -> t end module Ofday : sig type t val of_string : string -> t end type t val of_string : string -> t end
let run ( type zone ofday time ) time_m title f examples = let ( module Time : Time with type Zone . t = zone and type Ofday . t = ofday and type t = time ) = time_m in List . iter examples ~ f ( : fun ( zone , date , ofday , occurrences ) -> let time offset = Time . of_string ( sprintf " % s % s % s " date ofday offse...
let test time_m f = let go title examples = require_does_not_raise [ % here ] ( fun ( ) -> run time_m title f examples ; run time_m title f ( examples |> List . rev ) ) in let open Examples in go " same_day " same_day ; go " consecutive_days " consecutive_days ; go " non_consecutive_days " non_consecutive_days ; go " s...
module Date_and_ofday = struct type t = Date . t * Time . Ofday . t [ @@ deriving compare , sexp_of ] let equal = [ % compare . equal : t ] end
module Date_and_ofday_ns = struct type t = Date . t * Time_ns . Ofday . t [ @@ deriving compare , sexp_of ] let equal = [ % compare . equal : t ] end
module Time_precise = struct type t = [ ` Never of Time . t | ` Once of Time . t | ` Twice of Time . t * Time . t ] [ @@ deriving compare , sexp_of ] let equal = [ % compare . equal : t ] end
module Date_ofday_precise = struct type t = Date . t * Time . Ofday . t * [ ` Only | ` Also_at of Time . t | ` Also_skipped of Date . t * Time . Ofday . t ] [ @@ deriving compare , sexp_of ] let equal = [ % compare . equal : t ] end test ( module Time ) ( fun ~ title ~ zone ~ date ~ ofday ~ times -> match times with | ...
module Time_ns = struct include Time_ns module Span = struct include Span let of_int_ns i = i |> Int63 . of_int |> of_int63_ns end let sexp_of_t = Alternate_sexp . sexp_of_t end
let show t = print_s [ % sexp ( t : _ t ) ]
let gibi = 2 . ** 30 .
let gibi_nanos float = float . * gibi |> Time_ns . Span . of_ns
module Num_key_bits = struct open ! Private . Num_key_bits let % test_unit _ = invariant zero end
module Alarm_precision = struct include Alarm_precision let sexp_of_t t = [ % message " " ~ _ ( : t : t ) ~ _ : ( String . concat [ t |> to_span |> Time_ns . Span . to_int63_ns |> Int63 . to_string_hum ; " ns " ] ) ] ; ; let print t = print_s [ % sexp ( t : t ) ] let % expect_test " constants " = print about_one_day ; ...
let create_config ? extend_to_max_num_bits ? level_bits ~ alarm_precision ( ) = Config . create ( ) ~ alarm_precision ( : alarm_precision |> Alarm_precision . of_span_floor_pow2_ns ) ? level_bits : ( Option . map level_bits ~ f ( : Level_bits . create_exn ? extend_to_max_num_bits ) ) ; ; require_does_raise [ % here ] (...
let create_unit ? extend_to_max_num_bits ? level_bits ( ? start = Time_ns . epoch ) ( ? alarm_precision = gibi_nanos 1 . ) ( ) = create ~ config ( : create_config ? extend_to_max_num_bits ? level_bits ( ) ~ alarm_precision ) ~ start ; ; let test level_bits = let t = create_unit ( ) ~ level_bits in require_equal [ % her...
let advance_clock_to_interval_num t ~ to_ ~ handle_fired = advance_clock t ~ to_ ( : interval_num_start t to_ ) ~ handle_fired ; ; let t = create_unit ( ) ~ level_bits [ : 1 ] in let add ~ at = ignore ( add_at_interval_num t ~ at ( ) : _ Alarm . t ) in for interval_num = Interval_num . to_int_exn ( min_allowed_alarm_in...
let advance_clock_to_interval_num_return_removed_interval_nums t ~ to_ = let r = ref [ ] in let handle_fired alarm = r := Alarm . interval_num t alarm :: ! r in advance_clock_to_interval_num t ~ to_ ~ handle_fired ; ! r ; ; let t = create_unit ( ) ~ level_bits [ : 1 ] in let add ~ at = ignore ( add_at_interval_num t ~ ...
module Interval_num_option = struct type t = Interval_num . t option [ @@ deriving compare , sexp_of ] let equal = [ % compare . equal : t ] end let t = create_unit ( ) ~ level_bits [ : 1 ; 1 ; 1 ; 1 ] in require [ % here ] ( is_none ( min_alarm_interval_num t ) ) ; let _elt = add_at_interval_num t ~ at : Interval_num ...
let test_reschedule reschedule = let epoch_plus n_seconds = Time_ns . add Time_ns . epoch ( gibi_nanos n_seconds ) in let t = create ~ config ( : create_config ~ alarm_precision ( : gibi_nanos 1 . ) ~ level_bits [ : 10 ] ( ) ) ~ start ( : epoch_plus 0 . ) in let alarm1 = add t ~ at ( : epoch_plus 5 . ) ( ) in let alarm...
let wrap e = e >|= Environment . wrap_tzresult
let create_context ( ) = let accounts = Account . generate_accounts 1 in Block . alpha_context accounts >>=? fun ctxt -> match accounts with | [ ( { pkh ; _ } , _ ) ] -> return ( ctxt , pkh ) | _ -> assert false
let random_amount ( ) = match Tez . of_mutez ( Int64 . add 1L ( Random . int64 100L ) ) with | None -> assert false | Some x -> x
let test_simple_balances ( ) = Random . init 0 ; create_context ( ) >>=? fun ( ctxt , pkh ) -> let src = ` Contract ( Contract . implicit_contract pkh ) in let ( pkh , _pk , _sk ) = Signature . generate_key ( ) in let dest = ` Contract ( Contract . implicit_contract pkh ) in let amount = Tez . one in wrap ( Token . tra...