• 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

3.85
/src/lib/network_pool/test.ml
1
open Async_kernel
1✔
2
open Core_kernel
3
open Pipe_lib
4
open Network_peer
5

6
(* Only show stdout for failed inline tests. *)
7
open Inline_test_quiet_logs
8

9
let%test_module "network pool test" =
10
  ( module struct
11
    let trust_system = Mocks.trust_system
12

13
    let logger = Logger.null ()
×
14

15
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
16

17
    let constraint_constants = precomputed_values.constraint_constants
18

19
    let consensus_constants = precomputed_values.consensus_constants
20

21
    let proof_level = precomputed_values.proof_level
22

23
    let time_controller = Block_time.Controller.basic ~logger
24

25
    let block_window_duration =
26
      Mina_compile_config.For_unit_tests.t.block_window_duration
27

28
    let verifier =
29
      Async.Thread_safe.block_on_async_exn (fun () ->
×
30
          Verifier.create ~logger ~proof_level ~constraint_constants
×
31
            ~conf_dir:None
32
            ~pids:(Child_processes.Termination.create_pid_table ())
×
33
            ~commit_id:"not specified for unit tests" () )
34

35
    module Mock_snark_pool =
36
      Snark_pool.Make (Mocks.Base_ledger) (Mocks.Staged_ledger)
37
        (Mocks.Transition_frontier)
38

39
    let config =
40
      Mock_snark_pool.Resource_pool.make_config ~verifier ~trust_system
41
        ~disk_location:"/tmp/snark-pool"
42

43
    let%test_unit "Work that gets fed into apply_and_broadcast will be \
44
                   received in the pool's reader" =
45
      let tf = Mocks.Transition_frontier.create [] in
×
46
      let frontier_broadcast_pipe_r, _ = Broadcast_pipe.create (Some tf) in
×
47
      let work =
×
48
        `One
49
          (Quickcheck.random_value ~seed:(`Deterministic "network_pool_test")
×
50
             Transaction_snark.Statement.gen )
51
      in
52
      let priced_proof =
53
        { Priced_proof.proof =
54
            One_or_two.map ~f:Ledger_proof.For_tests.mk_dummy_proof work
×
55
        ; fee =
56
            { fee = Currency.Fee.zero
57
            ; prover = Signature_lib.Public_key.Compressed.empty
58
            }
59
        }
60
      in
61
      Async.Thread_safe.block_on_async_exn (fun () ->
62
          let network_pool, _, _ =
×
63
            Mock_snark_pool.create ~config ~logger ~constraint_constants
64
              ~consensus_constants ~time_controller
65
              ~frontier_broadcast_pipe:frontier_broadcast_pipe_r
66
              ~log_gossip_heard:false ~on_remote_push:(Fn.const Deferred.unit)
×
67
              ~block_window_duration
68
          in
69
          let%bind () =
70
            Mocks.Transition_frontier.refer_statements tf [ work ]
×
71
          in
72
          let command =
×
73
            Mock_snark_pool.Resource_pool.Diff.Add_solved_work
74
              (work, priced_proof)
75
          in
76
          Mock_snark_pool.apply_and_broadcast network_pool
77
            (Envelope.Incoming.local command)
×
78
            (Mock_snark_pool.Broadcast_callback.Local (Fn.const ())) ;
×
79
          let%map _ =
80
            Linear_pipe.read (Mock_snark_pool.broadcasts network_pool)
×
81
          in
82
          let pool = Mock_snark_pool.resource_pool network_pool in
×
83
          match Mock_snark_pool.Resource_pool.request_proof pool work with
×
84
          | Some { proof; fee = _ } ->
×
85
              assert (
×
86
                [%equal: Ledger_proof.t One_or_two.t] proof priced_proof.proof )
×
87
          | None ->
×
88
              failwith "There should have been a proof here" )
89

90
    let%test_unit "when creating a network, the incoming diffs and local diffs \
91
                   in the reader pipes will automatically get process" =
92
      let work_count = 10 in
×
93
      let works =
94
        Quickcheck.random_sequence ~seed:(`Deterministic "works")
×
95
          Transaction_snark.Statement.gen
96
        |> Fn.flip Sequence.take work_count
×
97
        |> Sequence.map ~f:(fun x -> `One x)
×
98
        |> Sequence.to_list
99
      in
100
      let per_reader = work_count / 2 in
×
101
      let create_work work =
102
        Mock_snark_pool.Resource_pool.Diff.Add_solved_work
×
103
          ( work
104
          , Priced_proof.
105
              { proof =
106
                  One_or_two.map ~f:Ledger_proof.For_tests.mk_dummy_proof work
×
107
              ; fee =
108
                  { fee = Currency.Fee.zero
109
                  ; prover = Signature_lib.Public_key.Compressed.empty
110
                  }
111
              } )
112
      in
113
      let verify_unsolved_work () =
114
        let%bind () = Async.Scheduler.yield_until_no_jobs_remain () in
×
115
        let tf = Mocks.Transition_frontier.create [] in
×
116
        let frontier_broadcast_pipe_r, _ = Broadcast_pipe.create (Some tf) in
×
117
        let network_pool, remote_sink, local_sink =
×
118
          Mock_snark_pool.create ~config ~logger ~constraint_constants
119
            ~consensus_constants ~time_controller
120
            ~frontier_broadcast_pipe:frontier_broadcast_pipe_r
121
            ~log_gossip_heard:false ~on_remote_push:(Fn.const Deferred.unit)
×
122
            ~block_window_duration
123
        in
124
        List.map (List.take works per_reader) ~f:create_work
×
125
        |> List.map ~f:(fun work ->
×
126
               ( Envelope.Incoming.local work
×
127
               , Mina_net2.Validation_callback.create_without_expiration () ) )
×
128
        |> List.iter ~f:(fun diff ->
129
               Mock_snark_pool.Remote_sink.push remote_sink diff
×
130
               |> Deferred.don't_wait_for ) ;
131
        List.map (List.drop works per_reader) ~f:create_work
×
132
        |> List.iter ~f:(fun diff ->
133
               Mock_snark_pool.Local_sink.push local_sink (diff, Fn.const ())
×
134
               |> Deferred.don't_wait_for ) ;
135
        let%bind () = Mocks.Transition_frontier.refer_statements tf works in
×
136
        don't_wait_for
×
137
        @@ Linear_pipe.iter (Mock_snark_pool.broadcasts network_pool)
×
138
             ~f:(fun With_nonce.{ message = work_command; _ } ->
139
               let work =
×
140
                 match work_command with
141
                 | Mock_snark_pool.Resource_pool.Diff.Add_solved_work (work, _)
×
142
                   ->
143
                     work
144
                 | Mock_snark_pool.Resource_pool.Diff.Empty ->
145
                     assert false
146
               in
147
               assert (
×
148
                 List.mem works work
×
149
                   ~equal:Transaction_snark_work.Statement.equal ) ;
150
               Deferred.unit ) ;
151
        Deferred.unit
×
152
      in
153
      verify_unsolved_work |> Async.Thread_safe.block_on_async_exn
154
  end )
1✔
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