From c67e6d4b041ba17da6a420b7f2b5339e1786c453 Mon Sep 17 00:00:00 2001 From: Pietro Date: Tue, 13 Feb 2018 17:01:33 +0100 Subject: [PATCH] Client/test: Add shell script to test protocol injection --- .gitlab-ci.yml | 5 ++ src/bin_client/test/demo/TEZOS_PROTOCOL | 3 + src/bin_client/test/demo/main.ml | 96 +++++++++++++++++++++++++ src/bin_client/test/jbuild | 18 ++++- src/bin_client/test/test_injection.sh | 18 +++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/bin_client/test/demo/TEZOS_PROTOCOL create mode 100644 src/bin_client/test/demo/main.ml create mode 100755 src/bin_client/test/test_injection.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 182e42ec0..1d4f6bc79 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -183,6 +183,11 @@ test:multinode.sh: script: - jbuilder build @src/bin_client/runtest_multinode.sh +test:inject.sh: + <<: *test_definition + script: + - jbuilder build @src/bin_client/runtest_injection.sh + test:proto:sandbox: <<: *test_definition script: diff --git a/src/bin_client/test/demo/TEZOS_PROTOCOL b/src/bin_client/test/demo/TEZOS_PROTOCOL new file mode 100644 index 000000000..9d31dc91c --- /dev/null +++ b/src/bin_client/test/demo/TEZOS_PROTOCOL @@ -0,0 +1,3 @@ +{ + "modules": ["Main"] +} diff --git a/src/bin_client/test/demo/main.ml b/src/bin_client/test/demo/main.ml new file mode 100644 index 000000000..e2ada9d96 --- /dev/null +++ b/src/bin_client/test/demo/main.ml @@ -0,0 +1,96 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +type operation = Operation_hash.t +let max_operation_data_length = 42 + +let max_block_length = 42 +let validation_passes = [] +let acceptable_passes _op = [] + +let parse_operation h _ = Ok h + +let compare_operations _ _ = 0 + +type validation_state = { + context : Context.t ; + fitness : Int64.t ; +} + +let current_context { context } = + return context + +module Fitness = struct + + type error += Invalid_fitness + type error += Invalid_fitness2 + + let int64_to_bytes i = + let b = MBytes.create 8 in + MBytes.set_int64 b 0 i; + b + + let int64_of_bytes b = + if Compare.Int.(MBytes.length b <> 8) then + fail Invalid_fitness2 + else + return (MBytes.get_int64 b 0) + + let from_int64 fitness = + [ int64_to_bytes fitness ] + + let to_int64 = function + | [ fitness ] -> int64_of_bytes fitness + | [] -> return 0L + | _ -> fail Invalid_fitness + + let get { fitness } = fitness + +end + +let precheck_block + ~ancestor_context:_ + ~ancestor_timestamp:_ + raw_block = + Fitness.to_int64 raw_block.Block_header.shell.fitness >>=? fun _ -> + return () + +let begin_application + ~predecessor_context:context + ~predecessor_timestamp:_ + ~predecessor_fitness:_ + raw_block = + Fitness.to_int64 raw_block.Block_header.shell.fitness >>=? fun fitness -> + return { context ; fitness } + +let begin_construction + ~predecessor_context:context + ~predecessor_timestamp:_ + ~predecessor_level:_ + ~predecessor_fitness:pred_fitness + ~predecessor:_ + ~timestamp:_ + ?proto_header:_ () = + Fitness.to_int64 pred_fitness >>=? fun pred_fitness -> + let fitness = Int64.succ pred_fitness in + return { context ; fitness } + +let apply_operation ctxt _ = + return ctxt + +let finalize_block ctxt = + let fitness = Fitness.get ctxt in + let message = Some (Format.asprintf "fitness <- %Ld" fitness) in + let fitness = Fitness.from_int64 fitness in + return { Updater.message ; context = ctxt.context ; fitness ; + max_operations_ttl = 0 ; max_operation_data_length = 0 } + +let rpc_services = RPC_directory.empty + +let configure_sandbox ctxt _ = Lwt.return (Ok ctxt) diff --git a/src/bin_client/test/jbuild b/src/bin_client/test/jbuild index 22a5811af..e7835d587 100644 --- a/src/bin_client/test/jbuild +++ b/src/bin_client/test/jbuild @@ -47,8 +47,24 @@ ${bin:tezos-client} )))) +(alias + ((name runtest_injection.sh) + (locks (/tcp-port/18731 + /tcp-port/19731)) + (deps (sandbox.json + test_lib.inc.sh + (glob_files demo/*) + )) + (action (run bash ${path:test_injection.sh} + ${bin:tezos-sandboxed-node.sh} + ${bin:tezos-node} + ${bin:tezos-init-sandboxed-client.sh} + ${bin:tezos-client} + )))) + (alias ((name runtest) (deps ((alias runtest_basic.sh) (alias runtest_contracts.sh) - (alias runtest_multinode.sh))))) + (alias runtest_multinode.sh) + (alias runtest_injection.sh))))) diff --git a/src/bin_client/test/test_injection.sh b/src/bin_client/test/test_injection.sh new file mode 100755 index 000000000..3aceab8ff --- /dev/null +++ b/src/bin_client/test/test_injection.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +set -e + +test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" +source $test_dir/test_lib.inc.sh "$@" + +start_node 1 + +sleep 2 +$client inject protocol "$test_dir/demo" +$client list protocols + +echo +echo End of test +echo + +show_logs="no"