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

MinaProtocol / mina / 2850

30 Oct 2024 07:56AM UTC coverage: 33.411% (-27.7%) from 61.098%
2850

push

buildkite

web-flow
Merge pull request #16306 from MinaProtocol/dkijania/fix_promotion_to_gcr

Fix promotion job PUBLISH misuse

22272 of 66661 relevant lines covered (33.41%)

129089.82 hits per line

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

43.33
/src/lib/codable/codable.ml
1
open Core_kernel
14✔
2

3
module type Iso_intf = sig
4
  type original
5

6
  type standardized [@@deriving yojson]
7

8
  val encode : original -> standardized
9

10
  val decode : standardized -> original
11
end
12

13
module type S = sig
14
  type t
15

16
  val to_yojson : t -> Yojson.Safe.t
17

18
  val of_yojson : Yojson.Safe.t -> t Ppx_deriving_yojson_runtime.error_or
19
end
20

21
module Make (Iso : Iso_intf) = struct
22
  let to_yojson t = Iso.encode t |> Iso.standardized_to_yojson
2,928✔
23

24
  let of_yojson json =
25
    Result.map ~f:Iso.decode (Iso.standardized_of_yojson json)
×
26

27
  module For_tests = struct
28
    let check_encoding t ~equal =
29
      match of_yojson (to_yojson t) with
×
30
      | Ok result ->
×
31
          equal t result
32
      | Error e ->
×
33
          failwithf !"%s" e ()
34
  end
35
end
36

37
module For_tests = struct
38
  let check_encoding (type t) (module M : S with type t = t) t ~equal =
39
    match M.of_yojson (M.to_yojson t) with
×
40
    | Ok result ->
×
41
        equal t result
42
    | Error e ->
×
43
        failwithf !"%s" e ()
44
end
45

46
module Make_of_int (Iso : sig
47
  type t
48

49
  val to_int : t -> int
50

51
  val of_int : int -> t
52
end) =
53
Make (struct
54
  type original = Iso.t
55

56
  type standardized = int [@@deriving yojson]
×
57

58
  let encode = Iso.to_int
59

60
  let decode = Iso.of_int
61
end)
62

63
module Make_of_string (Iso : sig
64
  type t
65

66
  val to_string : t -> string
67

68
  val of_string : string -> t
69
end) =
70
Make (struct
71
  type original = Iso.t
72

73
  type standardized = string [@@deriving yojson]
×
74

75
  let encode = Iso.to_string
76

77
  let decode = Iso.of_string
78
end)
79

80
module Make_base58_check (T : sig
81
  type t [@@deriving bin_io]
82

83
  val description : string
84

85
  val version_byte : char
86
end) =
87
struct
88
  module Base58_check = Base58_check.Make (T)
89

90
  let to_base58_check t = Base58_check.encode (Binable.to_string (module T) t)
162,216✔
91

92
  let of_base58_check s =
93
    let open Or_error.Let_syntax in
432✔
94
    let%bind decoded = Base58_check.decode s in
432✔
95
    Or_error.try_with (fun () -> Binable.of_string (module T) decoded)
432✔
96

97
  let of_base58_check_exn s = of_base58_check s |> Or_error.ok_exn
432✔
98

99
  let to_yojson t = `String (to_base58_check t)
6,698✔
100

101
  let of_yojson = function
102
    | `String s ->
×
103
        Result.map_error (of_base58_check s) ~f:Error.to_string_hum
×
104
    | json ->
×
105
        failwithf "of_yojson: expect JSON string, got %s"
106
          (Yojson.Safe.to_string json)
×
107
          ()
108
end
109

110
module type Base58_check_base_intf = sig
111
  type t
112

113
  (** Base58Check decoding *)
114
  val of_base58_check : string -> t Base.Or_error.t
115

116
  (** Base58Check decoding *)
117
  val of_base58_check_exn : string -> t
118
end
119

120
module type Base58_check_intf = sig
121
  type t
122

123
  (** explicit Base58Check encoding *)
124
  val to_base58_check : t -> string
125

126
  include Base58_check_base_intf with type t := t
127
end
128

129
module Make_base64 (T : sig
130
  type t [@@deriving bin_io]
131
end) =
132
struct
133
  let to_base64 (t : T.t) : string =
134
    Binable.to_string (module T) t
83✔
135
    |> (* raises only on errors from invalid optional arguments *)
136
    Base64.encode_exn
137

138
  let of_base64 b64 : T.t Or_error.t =
139
    match Base64.decode b64 with
42✔
140
    | Ok s -> (
42✔
141
        try Ok (Binable.of_string (module T) s)
42✔
142
        with Bin_prot.Common.Read_error _ as e ->
×
143
          Error (Error.of_exn ~backtrace:`Get e) )
×
144
    | Error (`Msg msg) ->
×
145
        Error (Error.of_string msg)
×
146
end
147

148
module type Base64_intf = sig
149
  type t
150

151
  val to_base64 : t -> string
152

153
  val of_base64 : string -> t Or_error.t
154
end
28✔
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