package octez-protocol-alpha-libs

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

Source file client_proto_tzt.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
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2023 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

open Protocol
open Alpha_context

type unit_test_with_source = {
  source : string;
  parsed : string Michelson_v1_parser.parser_result;
}

let print_stack out l = Michelson_v1_printer.print_typed_stack out l

let run_unit_test (cctxt : #Protocol_client_context.rpc_context)
    ~(chain : Chain_services.chain) ~block ~(test : unit_test_with_source) () =
  let open Lwt_result_syntax in
  let*? ut = Michelson_v1_stack.parse_unit_test test.parsed in
  let* chain_id = Chain_services.chain_id cctxt ~chain () in
  let amount = Tez.zero in
  let* expected_output =
    Plugin.RPC.Scripts.normalize_stack
      cctxt
      (chain, block)
      ~stack:ut.output
      ~unparsing_mode:Readable
      ~legacy:true
      ~other_contracts:None
      ~extra_big_maps:None
  in
  let* output, _gas =
    Plugin.RPC.Scripts.run_instr
      ~legacy:true
      ~gas:None
      ~input:ut.input
      ~code:ut.code
      ~now:None
      ~level:None
      ~sender:None
      ~source:None
      ~chain_id
      ~self:None
      ~parameter:None
      ~amount
      ~balance:None
      ~other_contracts:None
      ~extra_big_maps:None
      ~unparsing_mode:None
      cctxt
      (chain, block)
  in
  if output = expected_output then return_unit
  else
    failwith
      "Output: %a@.Expected: %a@."
      print_stack
      output
      print_stack
      expected_output
OCaml

Innovation. Community. Security.