diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index d82472539d744c5b3cd95bd3f2f0c8b00b5b9a0f..e832fb5fa60b90c264d69902dbccffd358f0948b 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -337,6 +337,7 @@ let estimated_gas_single (type kind) match result with | Applied res | Backtracked (res, _) -> ( match res with + | Increase_counter {consumed_gas; _} | Transaction_result ( Transaction_to_contract_result {consumed_gas; _} | Transaction_to_sc_rollup_result {consumed_gas; _} @@ -423,6 +424,7 @@ let estimated_storage_single (type kind) ~origination_size | Transaction_result (Transaction_to_sc_rollup_result _) | Reveal_result _ | Delegation_result _ | Increase_paid_storage_result _ | Dal_publish_slot_header_result _ | Sc_rollup_add_messages_result _ + | Increase_counter _ (* The following Sc_rollup operations have zero storage cost because we consider them to be paid in the stake deposit. @@ -502,12 +504,13 @@ let originated_contracts_single (type kind) ( Transaction_to_sc_rollup_result _ | Transaction_to_zk_rollup_result _ ) | Register_global_constant_result _ | Reveal_result _ - | Delegation_result _ | Update_consensus_key_result _ - | Increase_paid_storage_result _ | Transfer_ticket_result _ - | Dal_publish_slot_header_result _ | Sc_rollup_originate_result _ - | Sc_rollup_add_messages_result _ | Sc_rollup_cement_result _ - | Sc_rollup_publish_result _ | Sc_rollup_refute_result _ - | Sc_rollup_timeout_result _ | Sc_rollup_execute_outbox_message_result _ + | Increase_counter _ | Delegation_result _ + | Update_consensus_key_result _ | Increase_paid_storage_result _ + | Transfer_ticket_result _ | Dal_publish_slot_header_result _ + | Sc_rollup_originate_result _ | Sc_rollup_add_messages_result _ + | Sc_rollup_cement_result _ | Sc_rollup_publish_result _ + | Sc_rollup_refute_result _ | Sc_rollup_timeout_result _ + | Sc_rollup_execute_outbox_message_result _ | Sc_rollup_recover_bond_result _ | Zk_rollup_origination_result _ | Zk_rollup_publish_result _ | Zk_rollup_update_result _ -> return_nil) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index a5af9f2e7d639f072af10d0da9927e6de6d3af0d..7588a6da001809becf53df562f68bc4de4cc5bf7 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -201,6 +201,7 @@ let pp_manager_operation_content (type kind) source ppf source Signature.Public_key.pp key + | Increase_counter -> Format.fprintf ppf "Increase global counter by one" | Delegation delegate_opt -> ( Format.fprintf ppf "Delegation:@,Contract: %a@,To: " Contract.pp source ; match delegate_opt with @@ -633,6 +634,10 @@ let pp_operation_result ~operation_name pp_operation_result ppf = function (operation_name op_res) ; pp_operation_result ppf op_res +let pp_increase_counter ppf (Increase_counter {consumed_gas; new_counter}) = + pp_consumed_gas ppf consumed_gas ; + Format.fprintf ppf "@,Increased counter to: %d" @@ Z.to_int new_counter + let pp_manager_operation_contents_result ppf op_result = let pp_register_global_constant_result (Register_global_constant_result @@ -778,6 +783,7 @@ let pp_manager_operation_contents_result ppf op_result = (result : kind successful_manager_operation_result) = match result with | Reveal_result _ -> "revelation" + | Increase_counter _ -> "increase_counter" | Transaction_result _ -> "transaction" | Origination_result _ -> "origination" | Delegation_result _ -> "delegation" @@ -804,6 +810,7 @@ let pp_manager_operation_contents_result ppf op_result = (result : kind successful_manager_operation_result) = match result with | Reveal_result {consumed_gas} -> pp_consumed_gas ppf consumed_gas + | Increase_counter _ as op -> pp_increase_counter ppf op | Delegation_result {consumed_gas; balance_updates} -> pp_consumed_gas ppf consumed_gas ; pp_balance_updates ppf balance_updates diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 93f8575e610df731fe0b750f4f2223fa25f20525..6e5ea705e049804d2946e27f77cfdde8d2404d9b 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -3637,6 +3637,41 @@ let commands_rw () = ~fee_parameter () in + return_unit); + command + ~group + ~desc:"Inject the Increase_counter manager operation" + (args2 default_fee_arg fee_parameter_args) + (prefixes ["increase"; "counter"] + @@ Public_key_hash.source_param ~name:"src" ~desc:"the delegate key" + @@ stop) + (fun (fee, fee_parameter) src_pkh (cctxt : Protocol_client_context.full) -> + let open Lwt_result_syntax in + let* _ = + let* _, src_pk, src_sk = Client_keys.get_key cctxt src_pkh in + let operation = Increase_counter in + let operation = + Annotated_manager_operation.Single_manager + (Injection.prepare_manager_operation + ~fee:(Limit.of_option fee) + ~gas_limit:Limit.unknown + ~storage_limit:Limit.unknown + operation) + in + Injection.inject_manager_operation + cctxt + ~chain:cctxt#chain + ~block:cctxt#block + ~source:src_pkh + ~fee:(Limit.of_option fee) + ~gas_limit:Limit.unknown + ~storage_limit:Limit.unknown + ~src_pk + ~src_sk + ~fee_parameter + operation + in + return_unit); ] diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 35301a9490ac5457cb3871a13eb4e9248612a25a..56f99e6c1cb99b1c2d274bd48ab23dd8c6037558 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -207,10 +207,11 @@ "Sc_rollup_refutation_storage", "Zk_rollup_errors", + "Dummy_counter_storage", "Bootstrap_storage", "Init_storage", - "Destination_storage", + "Destination_storage", "Alpha_context", "Script_string", @@ -276,6 +277,7 @@ "Apply", "Services_registration", + "Dummy_counter_services", "Constants_services", "Sapling_services", "Contract_services", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 7a48a69be63ba849eb2bbe864bf810dae4b43dfa..160b565b69c46135de0b5dcee0ccd5115cf4d9c6 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -714,3 +714,7 @@ end module Internal_for_tests = struct let to_raw x = x end + +module Dummy_counter = struct + include Dummy_counter_storage +end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 8b655fdb76fbfd16250163c653abad2ab5b2b74d..8c98df89916f3bb0e604c2da102f9db2816ed265 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4265,6 +4265,8 @@ module Kind : sig type reveal = Reveal_kind + type increase_counter = Increase_counter_kind + type transaction = Transaction_kind type origination = Origination_kind @@ -4312,6 +4314,7 @@ module Kind : sig type 'a manager = | Reveal_manager_kind : reveal manager + | Increase_counter_manager_kind : increase_counter manager | Transaction_manager_kind : transaction manager | Origination_manager_kind : origination manager | Delegation_manager_kind : delegation manager @@ -4436,6 +4439,7 @@ and _ contents = and _ manager_operation = | Reveal : public_key -> Kind.reveal manager_operation + | Increase_counter : Kind.increase_counter manager_operation | Transaction : { amount : Tez.tez; parameters : Script.lazy_expr; @@ -4688,6 +4692,8 @@ module Operation : sig val reveal_case : Kind.reveal Kind.manager case + val increase_counter_case : Kind.increase_counter Kind.manager case + val transaction_case : Kind.transaction Kind.manager case val origination_case : Kind.origination Kind.manager case @@ -4747,6 +4753,8 @@ module Operation : sig val reveal_case : Kind.reveal case + val increase_counter_case : Kind.increase_counter case + val transaction_case : Kind.transaction case val origination_case : Kind.origination case @@ -5250,3 +5258,11 @@ module Fees : sig val check_storage_limit : context -> storage_limit:Z.t -> unit tzresult end + +module Dummy_counter : sig + val get : context -> Z.t option tzresult Lwt.t + + val get_or_init : context -> (context * Z.t, error trace) result Lwt.t + + val increase_counter : context -> (context, error trace) result Lwt.t +end diff --git a/src/proto_alpha/lib_protocol/alpha_services.ml b/src/proto_alpha/lib_protocol/alpha_services.ml index b7b33e8b7bf8b27b18f21eaa595e6da952ee2f0a..ec005198ad41ee3c28e3842f4dc3b7e4e95b1e34 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/alpha_services.ml @@ -336,6 +336,8 @@ module Denunciations = struct RPC_context.make_call0 S.denunciations ctxt block () () end +module Dummy_counter = Dummy_counter_services + let register () = Contract.register () ; Constants.register () ; @@ -347,4 +349,5 @@ let register () = Liquidity_baking.register () ; Cache.register () ; Adaptive_issuance.register () ; - Denunciations.register () + Denunciations.register () ; + Dummy_counter.register () diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 710b7bac1d37641620788cd4b390dac1022d42cb..50e70f26834f72d28b8d410d188c5a54bf1fd68c 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1123,6 +1123,16 @@ let apply_manager_operation : ~parameter:(Untyped_arg parameters) in (ctxt, Transaction_result res, ops) + | Increase_counter -> + let* ctxt = Dummy_counter.increase_counter ctxt in + let+ ctxt, counter = Dummy_counter.get_or_init ctxt in + ( ctxt, + Increase_counter + { + consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt; + new_counter = counter; + }, + [] ) | Transfer_ticket {contents; ty; ticketer; amount; destination; entrypoint} -> ( match destination with @@ -1691,6 +1701,7 @@ let burn_manager_storage_fees : size_of_constant = payload.size_of_constant; global_address = payload.global_address; } ) + | Increase_counter _ -> return (ctxt, storage_limit, smopr) | Update_consensus_key_result _ -> return (ctxt, storage_limit, smopr) | Increase_paid_storage_result _ -> return (ctxt, storage_limit, smopr) | Transfer_ticket_result payload -> diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 4c43948711b78b1de1900318a40cecf9f376f738..b9b34eb08da3c4ef3ad15451bf262757b98b710a 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -40,6 +40,11 @@ type _ successful_manager_operation_result = consumed_gas : Gas.Arith.fp; } -> Kind.reveal successful_manager_operation_result + | Increase_counter : { + consumed_gas : Gas.Arith.fp; + new_counter : Z.t; + } + -> Kind.increase_counter successful_manager_operation_result | Transaction_result : successful_transaction_result -> Kind.transaction successful_manager_operation_result @@ -267,6 +272,24 @@ module Manager_result = struct ~proj:(function Reveal_result {consumed_gas} -> consumed_gas) ~inj:(fun consumed_gas -> Reveal_result {consumed_gas}) + let increase_counter_case = + make + ~op_case:Operation.Encoding.Manager_operations.increase_counter_case + ~encoding: + Data_encoding.( + obj2 + (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) + (req "counter" z)) + ~select:(function + | Successful_manager_result (Increase_counter _ as op) -> Some op + | _ -> None) + ~kind:Kind.Increase_counter_manager_kind + ~proj:(function + | Increase_counter {consumed_gas; new_counter} -> + (consumed_gas, new_counter)) + ~inj:(fun (consumed_gas, new_counter) -> + Increase_counter {consumed_gas; new_counter}) + let transaction_contract_variant_cases = let case = function | Tag tag -> @@ -882,6 +905,7 @@ let successful_manager_operation_result_encoding : @@ union [ make Manager_result.reveal_case; + make Manager_result.increase_counter_case; make Manager_result.transaction_case; make Manager_result.origination_case; make Manager_result.delegation_case; @@ -957,6 +981,9 @@ let equal_manager_kind : match (ka, kb) with | Kind.Reveal_manager_kind, Kind.Reveal_manager_kind -> Some Eq | Kind.Reveal_manager_kind, _ -> None + | Kind.Increase_counter_manager_kind, Kind.Increase_counter_manager_kind -> + Some Eq + | Kind.Increase_counter_manager_kind, _ -> None | Kind.Transaction_manager_kind, Kind.Transaction_manager_kind -> Some Eq | Kind.Transaction_manager_kind, _ -> None | Kind.Origination_manager_kind, Kind.Origination_manager_kind -> Some Eq @@ -1523,6 +1550,17 @@ module Encoding = struct Some (op, res) | _ -> None) + let increase_counter_case = + make_manager_case + Operation.Encoding.increase_counter_case + Manager_result.increase_counter_case + (function + | Contents_and_result + ((Manager_operation {operation = Increase_counter; _} as op), res) + -> + Some (op, res) + | _ -> None) + let transaction_case = make_manager_case Operation.Encoding.transaction_case @@ -1745,6 +1783,7 @@ let common_cases = ballot_case; drain_delegate_case; reveal_case; + increase_counter_case; transaction_case; origination_case; delegation_case; @@ -2050,6 +2089,31 @@ let kind_equal : } ) -> Some Eq | Manager_operation {operation = Transaction _; _}, _ -> None + | ( Manager_operation {operation = Increase_counter; _}, + Manager_operation_result + {operation_result = Applied (Increase_counter _); _} ) -> + Some Eq + | ( Manager_operation {operation = Increase_counter; _}, + Manager_operation_result + {operation_result = Backtracked (Increase_counter _, _); _} ) -> + Some Eq + | ( Manager_operation {operation = Increase_counter; _}, + Manager_operation_result + { + operation_result = + Failed (Alpha_context.Kind.Increase_counter_manager_kind, _); + _; + } ) -> + Some Eq + | ( Manager_operation {operation = Increase_counter; _}, + Manager_operation_result + { + operation_result = + Skipped Alpha_context.Kind.Increase_counter_manager_kind; + _; + } ) -> + Some Eq + | Manager_operation {operation = Increase_counter; _}, _ -> None | ( Manager_operation {operation = Origination _; _}, Manager_operation_result {operation_result = Applied (Origination_result _); _} ) -> diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 1f8edf1eb8e93d440bb8238df0f3cb9da60ebaf3..b721f28fd02efea5ea156287604bc04372cf9b43 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -131,6 +131,11 @@ and _ successful_manager_operation_result = consumed_gas : Gas.Arith.fp; } -> Kind.reveal successful_manager_operation_result + | Increase_counter : { + consumed_gas : Gas.Arith.fp; + new_counter : Z.t; + } + -> Kind.increase_counter successful_manager_operation_result | Transaction_result : successful_transaction_result -> Kind.transaction successful_manager_operation_result diff --git a/src/proto_alpha/lib_protocol/dummy_counter_services.ml b/src/proto_alpha/lib_protocol/dummy_counter_services.ml new file mode 100644 index 0000000000000000000000000000000000000000..15dc469ab325b00a065cccc8dba43c64cefce9fc --- /dev/null +++ b/src/proto_alpha/lib_protocol/dummy_counter_services.ml @@ -0,0 +1,44 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trilitech *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Alpha_context + +module S = struct + let path = RPC_path.(open_root / "dummy_counter") + + let current_value = + RPC_service.get_service + ~description:"Current value of the global dummy counter" + ~query:RPC_query.empty + ~output:Data_encoding.z + RPC_path.(path / "get") +end + +let register () = + let open Lwt_result_syntax in + let open Services_registration in + register0 ~chunked:false S.current_value (fun ctxt () () -> + let* rez = Dummy_counter.get ctxt in + match rez with None -> return Z.zero | Some r -> return r) diff --git a/src/proto_alpha/lib_protocol/dummy_counter_services.mli b/src/proto_alpha/lib_protocol/dummy_counter_services.mli new file mode 100644 index 0000000000000000000000000000000000000000..6063600490c94de55df3ae64dfb754e93b958191 --- /dev/null +++ b/src/proto_alpha/lib_protocol/dummy_counter_services.mli @@ -0,0 +1,26 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trilitech *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +val register : unit -> unit diff --git a/src/proto_alpha/lib_protocol/dummy_counter_storage.ml b/src/proto_alpha/lib_protocol/dummy_counter_storage.ml new file mode 100644 index 0000000000000000000000000000000000000000..ebc6b2461e2edafa6c903d88a91572edd31bf485 --- /dev/null +++ b/src/proto_alpha/lib_protocol/dummy_counter_storage.ml @@ -0,0 +1,45 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trilitech *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Lwt_result_syntax + +(* TODO: investigate why using init without calling + find first crashes with [Missing key error] *) +let get = Storage.Dummy_counter_storage.find + +let get_or_init ctxt = + let* counter = get ctxt in + match counter with + | None -> + let* ctxt = Storage.Dummy_counter_storage.init ctxt Z.zero in + return (ctxt, Z.zero) + | Some counter -> return (ctxt, counter) + +let increase_counter ctxt = + let* ctxt, rez = get_or_init ctxt in + let*! ctxt = + Storage.Dummy_counter_storage.add ctxt @@ Z.add rez @@ Z.of_int 1 + in + return ctxt diff --git a/src/proto_alpha/lib_protocol/dummy_counter_storage.mli b/src/proto_alpha/lib_protocol/dummy_counter_storage.mli new file mode 100644 index 0000000000000000000000000000000000000000..00108ad52ea47a944115a24aaf1b45546a330090 --- /dev/null +++ b/src/proto_alpha/lib_protocol/dummy_counter_storage.mli @@ -0,0 +1,37 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trilitech *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(* Get the counter value, return None if it wasn't initialised *) +val get : Raw_context.t -> Z.t option tzresult Lwt.t + +(* Get the counter value. If it wasn't initialised, + initialise with the default value [0] *) +val get_or_init : + Raw_context.t -> (Raw_context.t * Z.t) tzresult Lwt.t + +(* Increasees the counter by [1] by using [get_or_init], + thus being initialised if needed *) +val increase_counter : + Raw_context.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 6cf514ca8cdc4a688ed2fa9fdec152a8bf6394d0..fe2ee1ab20bf571ce1f405f8b63441c6c9232417 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -218,6 +218,7 @@ Dal_slot_storage Sc_rollup_refutation_storage Zk_rollup_errors + Dummy_counter_storage Bootstrap_storage Init_storage Destination_storage @@ -278,6 +279,7 @@ Mempool_validation Apply Services_registration + Dummy_counter_services Constants_services Sapling_services Contract_services @@ -513,6 +515,7 @@ dal_slot_storage.ml dal_slot_storage.mli sc_rollup_refutation_storage.ml sc_rollup_refutation_storage.mli zk_rollup_errors.ml + dummy_counter_storage.ml dummy_counter_storage.mli bootstrap_storage.ml bootstrap_storage.mli init_storage.ml init_storage.mli destination_storage.ml destination_storage.mli @@ -573,6 +576,7 @@ mempool_validation.ml mempool_validation.mli apply.ml apply.mli services_registration.ml services_registration.mli + dummy_counter_services.ml dummy_counter_services.mli constants_services.ml constants_services.mli sapling_services.ml contract_services.ml contract_services.mli @@ -809,6 +813,7 @@ dal_slot_storage.ml dal_slot_storage.mli sc_rollup_refutation_storage.ml sc_rollup_refutation_storage.mli zk_rollup_errors.ml + dummy_counter_storage.ml dummy_counter_storage.mli bootstrap_storage.ml bootstrap_storage.mli init_storage.ml init_storage.mli destination_storage.ml destination_storage.mli @@ -869,6 +874,7 @@ mempool_validation.ml mempool_validation.mli apply.ml apply.mli services_registration.ml services_registration.mli + dummy_counter_services.ml dummy_counter_services.mli constants_services.ml constants_services.mli sapling_services.ml contract_services.ml contract_services.mli @@ -1089,6 +1095,7 @@ dal_slot_storage.ml dal_slot_storage.mli sc_rollup_refutation_storage.ml sc_rollup_refutation_storage.mli zk_rollup_errors.ml + dummy_counter_storage.ml dummy_counter_storage.mli bootstrap_storage.ml bootstrap_storage.mli init_storage.ml init_storage.mli destination_storage.ml destination_storage.mli @@ -1149,6 +1156,7 @@ mempool_validation.ml mempool_validation.mli apply.ml apply.mli services_registration.ml services_registration.mli + dummy_counter_services.ml dummy_counter_services.mli constants_services.ml constants_services.mli sapling_services.ml contract_services.ml contract_services.mli diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 1a9681d589cbecd132c61be9eeb87137b3ada9de..60e59ee2770d008605561d3f08f362afe98b282b 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -64,6 +64,8 @@ module Kind = struct type reveal = Reveal_kind + type increase_counter = Increase_counter_kind + type transaction = Transaction_kind type origination = Origination_kind @@ -111,6 +113,7 @@ module Kind = struct type 'a manager = | Reveal_manager_kind : reveal manager + | Increase_counter_manager_kind : increase_counter manager | Transaction_manager_kind : transaction manager | Origination_manager_kind : origination manager | Delegation_manager_kind : delegation manager @@ -300,6 +303,7 @@ and _ contents = and _ manager_operation = | Reveal : Signature.Public_key.t -> Kind.reveal manager_operation + | Increase_counter : Kind.increase_counter manager_operation | Transaction : { amount : Tez_repr.tez; parameters : Script_repr.lazy_expr; @@ -403,6 +407,7 @@ and _ manager_operation = let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function | Reveal _ -> Kind.Reveal_manager_kind + | Increase_counter -> Kind.Increase_counter_manager_kind | Transaction _ -> Kind.Transaction_manager_kind | Origination _ -> Kind.Origination_manager_kind | Delegation _ -> Kind.Delegation_manager_kind @@ -592,6 +597,18 @@ module Encoding = struct inj = (fun pkh -> Reveal pkh); } + let increase_counter_case = + MCase + { + tag = 123; + name = "increase_counter"; + encoding = Data_encoding.empty; + select = + (function Manager (Increase_counter as op) -> Some op | _ -> None); + proj = (function Increase_counter -> ()); + inj = (fun _ -> Increase_counter); + } + let transaction_case = MCase { @@ -1430,6 +1447,9 @@ module Encoding = struct inj = (fun (op, contents) -> rebuild op (mcase.inj contents)); } + let increase_counter_case = + make_manager_case 106 Manager_operations.increase_counter_case + let reveal_case = make_manager_case 107 Manager_operations.reveal_case let transaction_case = @@ -1528,6 +1548,7 @@ module Encoding = struct PCase proposals_case; PCase ballot_case; PCase reveal_case; + PCase increase_counter_case; PCase transaction_case; PCase origination_case; PCase delegation_case; @@ -1977,6 +1998,8 @@ let equal_manager_operation_kind : match (op1, op2) with | Reveal _, Reveal _ -> Some Eq | Reveal _, _ -> None + | Increase_counter, Increase_counter -> Some Eq + | Increase_counter, _ -> None | Transaction _, Transaction _ -> Some Eq | Transaction _, _ -> None | Origination _, Origination _ -> Some Eq diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index caccb54f0232def7dc2189b3c11c5822364abc50..bfeec95c31a71641930c23d30519592526b37f41 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -39,7 +39,7 @@ - failing noop - manager operation (which in turn has several types): - revelation - - transaction + - transaction - origination - delegation - set deposits limitation @@ -98,6 +98,8 @@ module Kind : sig type reveal = Reveal_kind + type increase_counter = Increase_counter_kind + type transaction = Transaction_kind type origination = Origination_kind @@ -145,6 +147,7 @@ module Kind : sig type 'a manager = | Reveal_manager_kind : reveal manager + | Increase_counter_manager_kind : increase_counter manager | Transaction_manager_kind : transaction manager | Origination_manager_kind : origination manager | Delegation_manager_kind : delegation manager @@ -337,6 +340,8 @@ and _ manager_operation = prerequisite to any signed operation, in order to be able to check the sender’s signature. *) | Reveal : Signature.Public_key.t -> Kind.reveal manager_operation + (* [Increase_counter] increses the special global chain constant *) + | Increase_counter : Kind.increase_counter manager_operation (* [Transaction] of some amount to some destination contract. It can also be used to execute/call smart-contracts. *) | Transaction : { @@ -708,6 +713,8 @@ module Encoding : sig val reveal_case : Kind.reveal Kind.manager case + val increase_counter_case : Kind.increase_counter Kind.manager case + val transaction_case : Kind.transaction Kind.manager case val origination_case : Kind.origination Kind.manager case @@ -765,6 +772,8 @@ module Encoding : sig val reveal_case : Kind.reveal case + val increase_counter_case : Kind.increase_counter case + val transaction_case : Kind.transaction case val origination_case : Kind.origination case diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 4fb55ad496ec7130c989e196f29cf18b966277db..855a3a882ae9cfb9d21e9f15a41d0c40d41e0e0e 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -2338,3 +2338,11 @@ module Legacy = struct end) (Tenderbake.Branch) end + +module Dummy_counter_storage : + Single_data_storage with type t = Raw_context.t with type value = Z.t = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["dummy_counter"] + end) + (Encoding.Z) diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 56a187abbc10f4f61d37307b3c7835829a2a6611..98dc77d6969313f730553b5877575d6574be2c86 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -1098,3 +1098,10 @@ module Legacy : sig with type value = Block_hash.t * Block_payload_hash.t and type t := Raw_context.t end + +(** Dummy counter storage + + Stores the integer value of the counter +*) +module Dummy_counter_storage : + Single_data_storage with type t = Raw_context.t with type value = Z.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index ef72163eca90029060606d833622b361863b9697..e75b136f33de02c310978543e0fd1eba189bbf2b 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -1069,7 +1069,7 @@ let balance_update_of_operation_result : match siopr with | Protocol.Apply_results.Transaction_result (Transaction_to_sc_rollup_result _) - | Reveal_result _ | Update_consensus_key_result _ + | Reveal_result _ | Update_consensus_key_result _ | Increase_counter _ | Transfer_ticket_result _ | Dal_publish_slot_header_result _ | Sc_rollup_originate_result _ | Sc_rollup_add_messages_result _ | Sc_rollup_cement_result _ | Sc_rollup_publish_result _ @@ -1178,6 +1178,7 @@ let bake_n_with_origination_results ?baking_mode ?policy n b = let open Apply_results in function | Successful_manager_result (Reveal_result _) + | Successful_manager_result (Increase_counter _) | Successful_manager_result (Delegation_result _) | Successful_manager_result (Update_consensus_key_result _) | Successful_manager_result (Transaction_result _) diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index ef6d9ec573b0235af42b238cc47bcc3bf3110964..db4e835a4d7a93c6814873dfb5487f6e43a0c48c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -75,6 +75,7 @@ type infos = {ctxt : ctxt; accounts : accounts; flags : feature_flags} new manager_operation kind. *) type manager_operation_kind = | K_Transaction + | K_Increase_counter | K_Origination | K_Register_global_constant | K_Delegation @@ -167,6 +168,7 @@ let operation_req_default kind = (** {2 String_of data} *) let kind_to_string = function | K_Transaction -> "Transaction" + | K_Increase_counter -> "Increase_counter" | K_Delegation -> "Delegation" | K_Undelegation -> "Undelegation" | K_Self_delegation -> "Self-delegation" @@ -976,6 +978,7 @@ let select_op (op_req : operation_req) (infos : infos) = let mk_op = match op_req.kind with | K_Transaction -> mk_transaction + | K_Increase_counter -> mk_transaction | K_Origination -> mk_origination | K_Register_global_constant -> mk_register_global_constant | K_Delegation -> mk_delegation @@ -1374,7 +1377,7 @@ let is_consumer = function | K_Zk_rollup_update -> false | K_Transaction | K_Origination | K_Register_global_constant - | K_Transfer_ticket -> + | K_Increase_counter | K_Transfer_ticket -> true let gas_consumer_in_validate_subjects, not_gas_consumer_in_validate_subjects = @@ -1388,6 +1391,7 @@ let is_disabled flags = function | K_Undelegation | K_Self_delegation | K_Update_consensus_key | K_Increase_paid_storage | K_Reveal | K_Transfer_ticket -> false + | K_Increase_counter -> false | K_Sc_rollup_origination | K_Sc_rollup_publish | K_Sc_rollup_cement | K_Sc_rollup_add_messages | K_Sc_rollup_refute | K_Sc_rollup_timeout | K_Sc_rollup_execute_outbox_message | K_Sc_rollup_recover_bond -> diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/test_sanity.ml b/src/proto_alpha/lib_protocol/test/integration/validate/test_sanity.ml index 439db456ea92017532ea4af097969f9e5b3011f8..143885cd74900f6cdacf36e0bff227b9a15ce79f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/test_sanity.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/test_sanity.ml @@ -58,6 +58,7 @@ let ensure_kind infos kind = match (operation, kind) with | Transaction _, K_Transaction | Reveal _, K_Reveal + | Increase_counter, K_Increase_counter | Origination _, K_Origination | Delegation _, K_Delegation | Delegation _, K_Undelegation @@ -80,10 +81,10 @@ let ensure_kind infos kind = | Zk_rollup_update _, K_Zk_rollup_update -> return_unit | ( ( Transaction _ | Origination _ | Register_global_constant _ - | Delegation _ | Update_consensus_key _ | Increase_paid_storage _ - | Reveal _ | Transfer_ticket _ | Sc_rollup_originate _ - | Sc_rollup_publish _ | Sc_rollup_cement _ | Sc_rollup_add_messages _ - | Sc_rollup_refute _ | Sc_rollup_timeout _ + | Increase_counter | Delegation _ | Update_consensus_key _ + | Increase_paid_storage _ | Reveal _ | Transfer_ticket _ + | Sc_rollup_originate _ | Sc_rollup_publish _ | Sc_rollup_cement _ + | Sc_rollup_add_messages _ | Sc_rollup_refute _ | Sc_rollup_timeout _ | Sc_rollup_execute_outbox_message _ | Sc_rollup_recover_bond _ | Dal_publish_slot_header _ | Zk_rollup_origination _ | Zk_rollup_publish _ | Zk_rollup_update _ ), diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index e57dc23b4dd0aab30a2edbd1fbe0f55eb0e1a9c6..8f014c064373b68beec4ad8a1c63f3838d36161f 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2113,6 +2113,7 @@ module Manager = struct consume_decoding_gas remaining_gas parameters in return_unit + | Increase_counter -> return_unit | Origination {script; _} -> let* remaining_gas = consume_decoding_gas remaining_gas script.code in let* (_ : Gas.Arith.fp) = diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml index 3326d63442e33e36c5197fab22042a55d48585de..abf17290b2cbe83bed734bd00730077b9609eb4b 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml @@ -322,7 +322,7 @@ let process_l1_operation (type kind) ~catching_up node_ctxt Sc_rollup.Address.( rollup = node_ctxt.Node_context.config.sc_rollup_address) | Dal_publish_slot_header _ -> true - | Reveal _ | Transaction _ | Origination _ | Delegation _ + | Reveal _ | Transaction _ | Origination _ | Delegation _ | Increase_counter | Update_consensus_key _ | Register_global_constant _ | Increase_paid_storage _ | Transfer_ticket _ | Sc_rollup_originate _ | Zk_rollup_origination _ | Zk_rollup_publish _ | Zk_rollup_update _ -> diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index bc1d6c702fca30d9da8aa3b1c861936144732bff..a293630104dbc906c1799601abb96bcfd12b0634 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -206,6 +206,12 @@ let get_chain_block_context_liquidity_baking_cpmm_address ?(chain = "main") ] JSON.as_string +let get_chain_context_dummy_counter ?(chain = "main") ?(block = "head") () = + make + GET + ["chains"; chain; "blocks"; block; "dummy_counter"; "get"] + JSON.as_int64 + let get_network_peer_untrust peer_id = make GET ["network"; "peers"; peer_id; "untrust"] Fun.id diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 9070ac5a45e18e32de1cbe85c0fc44648c27fc44..ff2a3dd0b29ba807ed54a8aeaa5ef7aeccca5f68 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -182,6 +182,14 @@ val get_chain_block_helper_round : val get_chain_block_context_liquidity_baking_cpmm_address : ?chain:string -> ?block:string -> unit -> string t +(** RPC: [GET /chains//blocks//context/dummy_counter/get] + + [chain] defaults to ["main"]. + [block] defaults to ["head"]. +*) +val get_chain_context_dummy_counter : + ?chain:string -> ?block:string -> unit -> int64 t + (** RPC: [GET /network/peers] *) val get_network_peers : (string * JSON.t) list t diff --git a/tezt/lib_tezos/operation_core.ml b/tezt/lib_tezos/operation_core.ml index 9c672d3a8ce2986e69df8fd57fd3494837b57adb..3172175f3664e298393b561547a30a1db53424be 100644 --- a/tezt/lib_tezos/operation_core.ml +++ b/tezt/lib_tezos/operation_core.ml @@ -569,6 +569,7 @@ module Manager = struct type transfer_parameters = {entrypoint : string; arg : JSON.u} type payload = + | Increase_counter | Reveal of Account.key | Transfer of { amount : int; @@ -589,6 +590,8 @@ module Manager = struct refutation : sc_rollup_refutation; } + let increase_counter = Increase_counter + let reveal account = Reveal account let transfer ?(dest = Constant.bootstrap2) ?(amount = 1_000_000) () = @@ -619,6 +622,7 @@ module Manager = struct } let json_payload_binding = function + | Increase_counter -> [("kind", `String "increase_counter")] | Reveal account -> [("kind", `String "reveal"); ("public_key", `String account.public_key)] | Transfer {amount; dest; parameters} -> @@ -710,6 +714,11 @@ module Manager = struct operation. They are close from the default values set by the client. *) match payload with + | Increase_counter -> + let fee = Option.value fee ~default:1_450 in + let gas_limit = Option.value gas_limit ~default:1_490 in + let storage_limit = Option.value storage_limit ~default:0 in + {source; counter; fee; gas_limit; storage_limit; payload} | Transfer _ -> let fee = Option.value fee ~default:1_000 in let gas_limit = Option.value gas_limit ~default:1_040 in diff --git a/tezt/lib_tezos/operation_core.mli b/tezt/lib_tezos/operation_core.mli index cc7eac16324cabf7611e3dc61d95609557b836d4..94b8714fe683459aaca6fd41a47ee0234e2d75d2 100644 --- a/tezt/lib_tezos/operation_core.mli +++ b/tezt/lib_tezos/operation_core.mli @@ -450,6 +450,9 @@ module Manager : sig common to all manager operations. See {!type:t}. *) type payload + (** Build an [Increase_counter] manager operation *) + val increase_counter : payload + (** Build a public key revelation. The [Account.key] argument has no default value because it will diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index b18b4c29d47d6907874e3a72cbf2bf9a8360f885..f32815f668215d44b7c3cb43bf16eb15f784a8f7 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -224,6 +224,7 @@ let register_protocol_specific_because_regression_tests () = Dal.register ~protocols:[Alpha] ; Evm_rollup.register ~protocols:[Alpha] ; Sc_sequencer.register ~protocols:[Alpha] ; + Protocol_dummy_counter.register ~protocols:[Alpha] ; (* This can be safely removed after Nairobi is frozen *) Timelock_disabled.register ~protocols:[Nairobi] diff --git a/tezt/tests/protocol_dummy_counter.ml b/tezt/tests/protocol_dummy_counter.ml new file mode 100644 index 0000000000000000000000000000000000000000..43d0315afa607c37486e4ad568b9f49f099420c7 --- /dev/null +++ b/tezt/tests/protocol_dummy_counter.ml @@ -0,0 +1,88 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trilitech *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(* Testing + ------- + Component: Protocol + Invocation: dune exec tezt/tests/main.exe -- --file protocol_dummy_counter.ml + Subject: Test the dummy counter functionalities, baking the manager operation and the rpc to get the value +*) + +let test_dummy_counter = + Protocol.register_test + ~__FILE__ + ~title:"protocol dummy counter" + ~tags:["mockup"; "protocol"; "counter"] + @@ fun protocol -> + let int_check arg expected ~__LOC__ = + Check.(arg = expected) + ~__LOC__ + Check.int64 + ~error_msg:"expected %R, but got %L" + in + let alice = Constant.bootstrap1 in + let bob = Constant.bootstrap2 in + (* Init node and client with alpha protocol *) + let* node, client = + Client.init_with_protocol + ~nodes_args:[Synchronisation_threshold 0] + ~protocol + `Client + () + in + (* Utility functions *) + let do_bake () = Client.bake_for_and_wait ~node client in + let rpc_get_counter () = + Client.RPC.call client @@ RPC.get_chain_context_dummy_counter () + in + let increase_op signer () = + let manager_op = Operation.Manager.(make ~source:signer increase_counter) in + let* manager_op = Operation.Manager.operation ~signer [manager_op] client in + Operation.inject manager_op client + in + let alice_op = increase_op alice in + let bob_op = increase_op bob in + (* Check value from rpc endpoint before any commands *) + let* res_0 = rpc_get_counter () in + int_check res_0 0L ~__LOC__ ; + (* Only alice increases counter *) + let* _ = alice_op () in + let* res_0 = rpc_get_counter () in + let* _ = do_bake () in + let* res_1 = rpc_get_counter () in + int_check res_0 0L ~__LOC__ ; + int_check res_1 1L ~__LOC__ ; + (* Alice injects two operations and Bob one *) + let* _ = alice_op () in + let* _ = alice_op () in + let* _ = bob_op () in + let* res_1 = rpc_get_counter () in + let* _ = do_bake () in + let* res_3 = rpc_get_counter () in + int_check res_1 1L ~__LOC__ ; + int_check res_3 3L ~__LOC__ ; + return () + +let register ~protocols = test_dummy_counter protocols