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

MinaProtocol / mina / 3409

26 Feb 2025 01:10PM UTC coverage: 32.353% (-28.4%) from 60.756%
3409

push

buildkite

web-flow
Merge pull request #16687 from MinaProtocol/dw/merge-compatible-into-develop-20250225

Merge compatible into develop [20250224]

23144 of 71535 relevant lines covered (32.35%)

16324.05 hits per line

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

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

6
let%test_module "network pool test" =
7
  ( module struct
8
    let trust_system = Mocks.trust_system
9

10
    let logger = Logger.null ()
×
11

12
    let precomputed_values = Lazy.force Precomputed_values.for_unit_tests
×
13

14
    let constraint_constants = precomputed_values.constraint_constants
15

16
    let consensus_constants = precomputed_values.consensus_constants
17

18
    let proof_level = precomputed_values.proof_level
19

20
    let time_controller = Block_time.Controller.basic ~logger
21

22
    let block_window_duration =
23
      Mina_compile_config.For_unit_tests.t.block_window_duration
24

25
    let verifier =
26
      Async.Thread_safe.block_on_async_exn (fun () ->
×
27
          Verifier.For_tests.default ~constraint_constants ~logger ~proof_level
×
28
            () )
29

30
    module Mock_snark_pool =
31
      Snark_pool.Make (Mocks.Base_ledger) (Mocks.Staged_ledger)
32
        (Mocks.Transition_frontier)
33

34
    let config =
35
      Mock_snark_pool.Resource_pool.make_config ~verifier ~trust_system
36
        ~disk_location:"/tmp/snark-pool"
37

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

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