• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 2863

05 Nov 2024 06:20PM UTC coverage: 30.754% (-16.6%) from 47.311%
2863

push

buildkite

web-flow
Merge pull request #16296 from MinaProtocol/dkijania/more_multi_jobs

more multi jobs in CI

20276 of 65930 relevant lines covered (30.75%)

8631.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.35
/src/lib/test_util/test_util.ml
1
open Core_kernel
9✔
2
open Fold_lib
3

4
module Make (Impl : Snarky_backendless.Snark_intf.S) = struct
5
  let triple_string trips =
6
    let to_string b = if b then "1" else "0" in
×
7
    String.concat ~sep:" "
8
      (List.map trips ~f:(fun (b1, b2, b3) ->
×
9
           to_string b1 ^ to_string b2 ^ to_string b3 ) )
×
10

11
  let checked_to_unchecked typ1 typ2 checked input =
12
    let open Impl in
×
13
    let checked_result =
14
      run_and_check
×
15
        (let%bind input = exists typ1 ~compute:(As_prover.return input) in
×
16
         let%map result = checked input in
×
17
         As_prover.read typ2 result )
×
18
      |> Or_error.ok_exn
19
    in
20
    checked_result
×
21

22
  let test_to_triples typ fold var_to_triples input =
23
    let open Impl in
×
24
    let checked =
25
      run_and_check
×
26
        (let%bind input = exists typ ~compute:(As_prover.return input) in
×
27
         let%map result = var_to_triples input in
×
28
         As_prover.all
×
29
           (List.map result
×
30
              ~f:
31
                (As_prover.read
×
32
                   (Typ.tuple3 Boolean.typ Boolean.typ Boolean.typ) ) ) )
×
33
      |> Or_error.ok_exn
34
    in
35
    let unchecked = Fold.to_list (fold input) in
×
36
    if not ([%equal: (bool * bool * bool) list] checked unchecked) then
×
37
      failwithf
×
38
        !"Got %s (%d)\nexpected %s (%d)"
39
        (triple_string checked) (List.length checked) (triple_string unchecked)
×
40
        (List.length unchecked) ()
×
41

42
  let test_equal ?(equal = Poly.( = )) typ1 typ2 checked unchecked input =
×
43
    let checked_result = checked_to_unchecked typ1 typ2 checked input in
×
44
    assert (equal checked_result (unchecked input))
×
45

46
  let arbitrary_string ~len =
47
    String.init (Random.int len) ~f:(fun _ ->
×
48
        Char.of_int_exn (Random.int_incl 0 255) )
×
49

50
  let with_randomness r f =
51
    let s = Caml.Random.get_state () in
×
52
    Random.init r ;
×
53
    try
×
54
      let x = f () in
55
      Caml.Random.set_state s ; x
×
56
    with e -> Caml.Random.set_state s ; raise e
×
57

58
  (** utility function to print digests to put in tests, see `check_serialization' below *)
59
  let print_digest digest = printf "\"" ; printf "%s" digest ; printf "\"\n%!"
×
60

61
  (** use this function to test Bin_prot serialization of types *)
62
  let check_serialization (type t) (module M : Binable.S with type t = t)
63
      (t : t) known_good_digest =
64
    (* serialize value *)
65
    let sz = M.bin_size_t t in
×
66
    let buf = Bin_prot.Common.create_buf sz in
×
67
    ignore (M.bin_write_t buf ~pos:0 t : int) ;
×
68
    let bytes = Bytes.create sz in
69
    Bin_prot.Common.blit_buf_bytes buf bytes ~len:sz ;
×
70
    (* compute MD5 digest of serialization *)
71
    let digest = Md5.digest_bytes bytes |> Md5.to_hex in
×
72
    let result = String.equal digest known_good_digest in
×
73
    if not result then (
×
74
      printf "Expected digest: " ;
75
      print_digest known_good_digest ;
×
76
      printf "Got digest:      " ;
×
77
      print_digest digest ) ;
×
78
    result
×
79
end
80

81
include Make (Snark_params.Tick)
18✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc