• 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

14.04
/src/lib/network_peer/envelope.ml
1
open Core
7✔
2

3
module Sender = struct
4
  type t = Local | Remote of Peer.t [@@deriving sexp, compare]
×
5

6
  let of_peer (p : Peer.t) = Remote p
6✔
7

8
  let equal sender1 sender2 = Int.equal (compare sender1 sender2) 0
×
9

10
  let to_yojson t : Yojson.Safe.t =
11
    match t with
×
12
    | Local ->
×
13
        `String "Local"
14
    | Remote p ->
×
15
        `Assoc [ ("Remote", Peer.to_yojson p) ]
×
16

17
  let of_yojson (json : Yojson.Safe.t) : (t, string) Result.t =
18
    match json with
×
19
    | `String "Local" ->
×
20
        Ok Local
21
    | `Assoc [ ("Remote", peer_json) ] ->
×
22
        let open Result.Let_syntax in
23
        let%map peer = Peer.of_yojson peer_json in
×
24
        Remote peer
×
25
    | _ ->
×
26
        Error "Expected JSON representing envelope sender"
27

28
  let remote_exn = function
29
    | Local ->
×
30
        failwith "Sender.remote_exn of Local sender"
31
    | Remote x ->
×
32
        x
33

34
  let gen : t Quickcheck.Generator.t =
35
    let open Quickcheck.Generator.Let_syntax in
36
    let%bind ip =
37
      match%map
38
        Quickcheck.Generator.(
39
          variant2
7✔
40
            (list_with_length 4 (Int.gen_incl 0 255))
7✔
41
            (list_with_length 8 (Int.gen_incl 0 65535)))
7✔
42
      with
43
      | `A octets ->
×
44
          String.concat ~sep:"." (List.map ~f:Int.to_string octets)
×
45
      | `B segments ->
×
46
          String.concat ~sep:":" (List.map ~f:(Printf.sprintf "%x") segments)
×
47
    in
48
    let remote =
×
49
      let inet = Unix.Inet_addr.of_string ip in
50
      let%bind peer_id = String.gen_nonempty in
51
      let%map libp2p_port = Int.gen_uniform_incl 1025 49151 in
×
52
      Peer.create inet ~peer_id ~libp2p_port
×
53
    in
54
    match%map Option.quickcheck_generator remote with
×
55
    | None ->
×
56
        Local
57
    | Some remote ->
×
58
        Remote remote
59
end
60

61
module Incoming = struct
62
  let time_to_yojson tm = `String (Time.to_string tm)
×
63

64
  let time_of_yojson = function
65
    | `String s ->
×
66
        Ok (Time.of_string s)
×
67
    | _ ->
×
68
        Error "time_of_yojson: Expected string"
69

70
  type 'a t =
×
71
    { data : 'a
×
72
    ; sender : Sender.t
×
73
    ; received_at : Time.t
×
74
          [@to_yojson time_to_yojson] [@of_yojson time_of_yojson]
×
75
    }
76
  [@@deriving equal, sexp, yojson, compare]
77

78
  let sender t = t.sender
×
79

80
  let data t = t.data
×
81

82
  let received_at t = t.received_at
×
83

84
  let wrap ~data ~sender =
85
    let received_at = Time.now () in
×
86
    { data; sender; received_at }
×
87

88
  let wrap_peer ~data ~sender =
89
    let received_at = Time.now () in
6✔
90
    { data; sender = Sender.of_peer sender; received_at }
6✔
91

92
  let map ~f t = { t with data = f t.data }
×
93

94
  let lift_error t =
95
    let open Result.Let_syntax in
×
96
    let%map data = t.data in
97
    { t with data }
×
98

99
  let local data =
100
    let received_at = Time.now () in
×
101
    let sender = Sender.Local in
×
102
    { data; sender; received_at }
103

104
  let remote_sender_exn t =
105
    match t.sender with
×
106
    | Local ->
×
107
        failwith "Incoming.sender_sender_exn of Local envelope"
108
    | Remote x ->
×
109
        x
110

111
  let gen gen_a =
112
    let open Quickcheck.Generator.Let_syntax in
×
113
    let%bind data = gen_a in
114
    let%map sender = Sender.gen in
115
    let received_at = Time.now () in
×
116
    { data; sender; received_at }
×
117
end
14✔
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