From 4105467603295ed943c6a84bdb49a71d1e18b8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 4 Jun 2018 14:46:50 +0200 Subject: [PATCH] Alpha: changes needed for test framework --- src/proto_alpha/lib_protocol/src/alpha_context.mli | 11 ++++++++++- src/proto_alpha/lib_protocol/src/baking.ml | 4 ++-- src/proto_alpha/lib_protocol/src/block_header_repr.ml | 7 +++++++ .../lib_protocol/src/block_header_repr.mli | 2 ++ .../lib_protocol/src/constants_services.mli | 1 + src/proto_alpha/lib_protocol/src/operation_repr.ml | 8 ++++++++ src/proto_alpha/lib_protocol/src/operation_repr.mli | 2 ++ 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index e1f9c6bc4..d1716b1f5 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -335,7 +335,6 @@ module Constants : sig } val parametric_encoding: parametric Data_encoding.t val parametric: context -> parametric - val preserved_cycles: context -> int val blocks_per_cycle: context -> int32 val blocks_per_commitment: context -> int32 @@ -361,6 +360,7 @@ module Constants : sig val block_security_deposit: context -> Tez.t val endorsement_security_deposit: context -> Tez.t + (** All constants: fixed and parametric *) type t = { fixed : fixed ; parametric : parametric ; @@ -577,6 +577,12 @@ module Contract : sig context -> contract -> string -> (context * Script_repr.expr option) tzresult Lwt.t end + (**/**) + (* Only for testing *) + type origination_nonce + val initial_origination_nonce : Operation_hash.t -> origination_nonce + val originated_contract : origination_nonce -> contract + end module Delegate : sig @@ -701,6 +707,8 @@ module Block_header : sig type raw = Block_header.t type shell_header = Block_header.shell_header + val raw: block_header -> raw + val hash: block_header -> Block_hash.t val hash_raw: raw -> Block_hash.t @@ -831,6 +839,7 @@ module Operation : sig shell: Operation.shell_header ; protocol_data: protocol_data ; } + val raw: operation -> raw val encoding: operation Data_encoding.t val hash: operation -> Operation_hash.t diff --git a/src/proto_alpha/lib_protocol/src/baking.ml b/src/proto_alpha/lib_protocol/src/baking.ml index dd8a129b7..18ecf5cd3 100644 --- a/src/proto_alpha/lib_protocol/src/baking.ml +++ b/src/proto_alpha/lib_protocol/src/baking.ml @@ -194,14 +194,14 @@ let check_endorsements_rights c level slots = let paying_priorities c = 0 --> (Constants.first_free_baking_slot c - 1) -type error += Incorect_priority +type error += Incorrect_priority let endorsement_reward ctxt ~block_priority:prio = if Compare.Int.(prio >= 0) then Lwt.return Tez.(Constants.endorsement_reward ctxt /? (Int64.(succ (of_int prio)))) - else fail Incorect_priority + else fail Incorrect_priority let baking_priorities c level = let rec f priority = diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.ml b/src/proto_alpha/lib_protocol/src/block_header_repr.ml index fe627e69b..1a2de1c1c 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.ml @@ -55,6 +55,13 @@ let protocol_data_encoding = contents_encoding (obj1 (req "signature" Signature.encoding))) +let raw { shell ; protocol_data ; } = + let protocol_data = + Data_encoding.Binary.to_bytes_exn + protocol_data_encoding + protocol_data in + { Block_header.shell ; protocol_data } + let unsigned_encoding = let open Data_encoding in merge_objs diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.mli b/src/proto_alpha/lib_protocol/src/block_header_repr.mli index 70966d3b5..8bebe69c9 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.mli @@ -28,6 +28,8 @@ type block_header = t type raw = Block_header.t type shell_header = Block_header.shell_header +val raw: block_header -> raw + val encoding: block_header Data_encoding.encoding val raw_encoding: raw Data_encoding.t val contents_encoding: contents Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/src/constants_services.mli b/src/proto_alpha/lib_protocol/src/constants_services.mli index b48636704..9cc0e4dd5 100644 --- a/src/proto_alpha/lib_protocol/src/constants_services.mli +++ b/src/proto_alpha/lib_protocol/src/constants_services.mli @@ -66,5 +66,6 @@ val endorsement_reward: val errors: 'a #RPC_context.simple -> 'a -> Data_encoding.json_schema shell_tzresult Lwt.t +(** Returns all the constants of the protocol *) val all: 'a #RPC_context.simple -> 'a -> Constants.t shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.ml b/src/proto_alpha/lib_protocol/src/operation_repr.ml index d06778bfe..03509be9c 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/src/operation_repr.ml @@ -451,6 +451,14 @@ let protocol_data_encoding = Encoding.protocol_data_encoding let unsigned_operation_encoding = Encoding.unsigned_operation_encoding let internal_operation_encoding = Encoding.internal_operation_encoding +let raw { shell ; protocol_data } = + let proto = + Data_encoding.Binary.to_bytes_exn + protocol_data_encoding + protocol_data in + { Operation.shell ; proto } + + let acceptable_passes op = match op.protocol_data.contents with | Sourced_operation (Consensus_operation _) -> [0] diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.mli b/src/proto_alpha/lib_protocol/src/operation_repr.mli index 4f1bec011..9b918891e 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/src/operation_repr.mli @@ -111,6 +111,8 @@ val contents_encoding: contents Data_encoding.t val protocol_data_encoding: protocol_data Data_encoding.t val unsigned_operation_encoding: (Operation.shell_header * contents) Data_encoding.t +val raw: operation -> raw + val hash_raw: raw -> Operation_hash.t val hash: operation -> Operation_hash.t