Proto_alpha: added test for raw_context rpc call
This commit is contained in:
parent
ce93c266e5
commit
54f0e21373
@ -5,6 +5,7 @@
|
||||
test_michelson_parser
|
||||
test_origination
|
||||
test_transaction
|
||||
test_rpc
|
||||
test_vote))
|
||||
(libraries (tezos-base
|
||||
tezos-rpc-http
|
||||
@ -31,6 +32,7 @@
|
||||
test_michelson_parser.exe
|
||||
test_origination.exe
|
||||
test_transaction.exe
|
||||
test_rpc.exe
|
||||
test_vote.exe))))
|
||||
|
||||
(alias
|
||||
@ -57,12 +59,18 @@
|
||||
(locks (/tcp-port/18400))
|
||||
(action (chdir ${ROOT} (run ${exe:test_vote.exe} ${bin:tezos-node} ${path:sandbox-vote.json} 18400)))))
|
||||
|
||||
(alias
|
||||
((name runtest_rpc)
|
||||
(locks (/tcp-port/18500))
|
||||
(action (chdir ${ROOT} (run ${exe:test_rpc.exe} ${bin:tezos-node} ${path:sandbox.json} 18500)))))
|
||||
|
||||
(alias
|
||||
((name runtest)
|
||||
(deps ((alias runtest_endorsement)
|
||||
(alias runtest_michelson_parser)
|
||||
(alias runtest_origination)
|
||||
(alias runtest_transaction)
|
||||
(alias runtest_rpc)
|
||||
(alias runtest_vote)))))
|
||||
|
||||
(alias
|
||||
|
@ -75,6 +75,9 @@ let init ?exe ?(sandbox = "sandbox.json") ?rpc_port () =
|
||||
let level block =
|
||||
Alpha_services.Context.level !rpc_ctxt block
|
||||
|
||||
let rpc_raw_context block path depth =
|
||||
Block_services.raw_context !rpc_ctxt block path depth
|
||||
|
||||
module Account = struct
|
||||
|
||||
type t = {
|
||||
|
@ -21,6 +21,10 @@ val init :
|
||||
|
||||
val level : Block_services.block -> Alpha_context.Level.t tzresult Lwt.t
|
||||
|
||||
(** Calls the rpc service raw_context using the right rpc context *)
|
||||
val rpc_raw_context : Block_services.block -> string list -> int ->
|
||||
Block_services.raw_context_result tzresult Lwt.t
|
||||
|
||||
module Account : sig
|
||||
|
||||
type t = {
|
||||
|
77
src/proto_alpha/lib_baking/test/test_rpc.ml
Normal file
77
src/proto_alpha/lib_baking/test/test_rpc.ml
Normal file
@ -0,0 +1,77 @@
|
||||
(**************************************************************************)
|
||||
(* *)
|
||||
(* Copyright (c) 2014 - 2018. *)
|
||||
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||
(* *)
|
||||
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
module Helpers = Proto_alpha_helpers
|
||||
module Assert = Helpers.Assert
|
||||
|
||||
(* Test for the rpc call Block_services.raw_context
|
||||
A similar test is bin_client/test/test_basic.sh
|
||||
*)
|
||||
let run blkid =
|
||||
let open Block_services in
|
||||
|
||||
let is_equal a = function
|
||||
| Ok b -> a = b
|
||||
| _ -> false
|
||||
in
|
||||
let is_not_found : raw_context_result tzresult -> bool = function
|
||||
| Error [RPC_context.Not_found _] -> true
|
||||
| _ -> false
|
||||
in
|
||||
|
||||
(* files and directories that are in context *)
|
||||
let version = Key (MBytes.of_hex (`Hex "67656e65736973")) in
|
||||
let genesis_key = Key (MBytes.of_hex (`Hex "68b4bf512517497dbd944de6825ab0a0fed7ff51bdd6b77596a19cc9175ddd55")) in
|
||||
let dir_depth0 = Cut in
|
||||
let dir_depth1 = Dir [("genesis_key", Cut);
|
||||
("v1", Cut);
|
||||
("version", Cut)] in
|
||||
let dir_depth2 = Dir [("genesis_key", genesis_key);
|
||||
("v1", Dir [("sandboxed",Cut)]);
|
||||
("version", version)] in
|
||||
|
||||
let tests = [(("version",1), is_equal version);
|
||||
(("",0), is_equal dir_depth0);
|
||||
(("",1), is_equal dir_depth1);
|
||||
(("",2), is_equal dir_depth2);
|
||||
(("",2), is_equal dir_depth2);
|
||||
(("",-1), is_not_found);
|
||||
(("not-existent",1), is_not_found);
|
||||
(("not-existent",0), is_not_found);
|
||||
(("not-existent",-1), is_not_found);
|
||||
] in
|
||||
iter_s (fun ((path,depth),predicate) ->
|
||||
Helpers.rpc_raw_context blkid [path] depth >>= fun result ->
|
||||
return (assert (predicate result))
|
||||
) tests
|
||||
|
||||
let exe = try Sys.argv.(1) with _ -> "tezos-node"
|
||||
let sandbox = try Sys.argv.(2) with _ -> "sandbox.json"
|
||||
let rpc_port = try int_of_string Sys.argv.(3) with _ -> 18500
|
||||
|
||||
let main () =
|
||||
Helpers.init ~exe ~sandbox ~rpc_port () >>=? fun (_node_pid, genesis) ->
|
||||
run (`Hash genesis)
|
||||
|
||||
let tests = [
|
||||
"main", (fun _ -> main ()) ;
|
||||
]
|
||||
|
||||
let wrap (n, f) =
|
||||
Alcotest_lwt.test_case n `Quick begin fun _ () ->
|
||||
f () >>= function
|
||||
| Ok () -> Lwt.return_unit
|
||||
| Error error ->
|
||||
Format.kasprintf Pervasives.failwith "%a" pp_print_error error
|
||||
end
|
||||
|
||||
let () =
|
||||
Alcotest.run ~argv:[|""|] "tezos-client-alpha" [
|
||||
"rpcs", List.map wrap tests
|
||||
]
|
Loading…
Reference in New Issue
Block a user