package tezos-test-helpers-extra

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file assert_lib.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2020 Nomadic Labs. <contact@nomadic-labs.com>               *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

(** [assert_lib] contains Alcotest convenience assertions depending on Tezos_base. *)

module Assert = Tezos_test_helpers.Assert

module Crypto = struct
  let equal_operation ?loc ?msg op1 op2 =
    let eq = Option.equal Tezos_base.Operation.equal in
    let pp ppf = function
      | None -> Format.pp_print_string ppf "none"
      | Some op ->
          Format.pp_print_string ppf
          @@ Tezos_crypto.Hashed.Operation_hash.to_b58check
               (Tezos_base.Operation.hash op)
    in
    Assert.equal ?loc ?msg ~pp ~eq op1 op2

  let equal_block ?loc ?msg st1 st2 =
    let eq st1 st2 = Tezos_base.Block_header.equal st1 st2 in
    let pp ppf st =
      Format.fprintf
        ppf
        "@[<v 2>%a@ %a@]"
        Tezos_crypto.Hashed.Block_hash.pp
        (Tezos_base.Block_header.hash st)
        Data_encoding.Json.pp
        (Data_encoding.Json.construct Tezos_base.Block_header.encoding st)
    in
    Assert.equal ?loc ?msg ~pp ~eq st1 st2

  let equal_block_set ?loc ?msg set1 set2 =
    let b1 = Tezos_crypto.Hashed.Block_hash.Set.elements set1
    and b2 = Tezos_crypto.Hashed.Block_hash.Set.elements set2 in
    Assert.equal_list
      ?loc
      ?msg
      ~eq:Tezos_crypto.Hashed.Block_hash.equal
      ~pp:Tezos_crypto.Hashed.Block_hash.pp
      b1
      b2

  let equal_block_map ~eq ?loc ?msg map1 map2 =
    let b1 = Tezos_crypto.Hashed.Block_hash.Map.bindings map1
    and b2 = Tezos_crypto.Hashed.Block_hash.Map.bindings map2 in
    Assert.equal_list
      ?loc
      ?msg
      ~eq:(fun (h1, b1) (h2, b2) ->
        Tezos_crypto.Hashed.Block_hash.equal h1 h2 && eq b1 b2)
      ~pp:(fun ppf (h, _) -> Tezos_crypto.Hashed.Block_hash.pp ppf h)
      b1
      b2

  let equal_block_hash_list ?loc ?msg l1 l2 =
    let pp = Tezos_crypto.Hashed.Block_hash.pp_short in
    Assert.equal_list
      ?loc
      ?msg
      ~eq:Tezos_crypto.Hashed.Block_hash.equal
      ~pp
      l1
      l2

  let equal_block_descriptor ?loc ?msg bd1 bd2 =
    let eq (l1, h1) (l2, h2) =
      Int32.equal l1 l2 && Tezos_crypto.Hashed.Block_hash.equal h1 h2
    in
    let pp ppf (l, h) =
      Format.fprintf ppf "(%ld, %a)" l Tezos_crypto.Hashed.Block_hash.pp h
    in
    Assert.equal ?loc ?msg ~pp ~eq bd1 bd2
end

module Raw_Tree = struct
  let equal ?loc ?msg r1 r2 =
    let rec aux r1 r2 =
      match (r1, r2) with
      | `Value v1, `Value v2 ->
          Assert.Bytes.equal ?loc ?msg v1 v2 ;
          true
      | `Tree t1, `Tree t2 ->
          if not (Tezos_base.TzPervasives.String.Map.equal aux t1 t2) then
            Assert.String.fail "<tree>" "<tree>" ?msg ?loc
          else true
      | `Tree _, `Value v ->
          Assert.String.fail ?loc ?msg "<tree>" (Bytes.to_string v)
      | `Value v, `Tree _ ->
          Assert.String.fail ?loc ?msg (Bytes.to_string v) "<tree>"
    in
    let _b : bool = aux r1 r2 in
    ()
end
OCaml

Innovation. Community. Security.