From 10157c977ca2e8ed2cf78db2dd354998368f506c Mon Sep 17 00:00:00 2001 From: vbot Date: Tue, 1 Dec 2020 18:06:12 +0100 Subject: [PATCH 01/20] Shell: allow validator to receive a block in the future if forced --- src/lib_shell/validator.ml | 69 ++++++++++++--------- src/lib_shell_services/validation_errors.ml | 2 +- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/lib_shell/validator.ml b/src/lib_shell/validator.ml index b9260878d92f..5ce6a72b20fb 100644 --- a/src/lib_shell/validator.ml +++ b/src/lib_shell/validator.ml @@ -103,41 +103,48 @@ let validate_block v ?(force = false) ?chain_id bytes operations = | None -> failwith "Cannot parse block header." | Some block -> - if not (Clock_drift.is_not_too_far_in_the_future block.shell.timestamp) - then failwith "Block in the future." - else - ( match chain_id with - | None -> ( - Distributed_db.read_block_header v.db block.shell.predecessor + fail_unless + ( force + || Clock_drift.is_not_too_far_in_the_future block.shell.timestamp ) + (Validation_errors.Future_block_header + { + block = hash; + time = Systime_os.now (); + block_time = block.shell.timestamp; + }) + >>=? fun () -> + ( match chain_id with + | None -> ( + Distributed_db.read_block_header v.db block.shell.predecessor + >>= function + | None -> + failwith + "Unknown predecessor (%a), cannot inject the block." + Block_hash.pp_short + block.shell.predecessor + | Some (chain_id, _bh) -> + Lwt.return (get v chain_id) ) + | Some chain_id -> ( + Lwt.return (get v chain_id) + >>=? fun nv -> + if force then return nv + else + Distributed_db.Block_header.known + (Chain_validator.chain_db nv) + block.shell.predecessor >>= function - | None -> + | true -> + return nv + | false -> failwith "Unknown predecessor (%a), cannot inject the block." Block_hash.pp_short - block.shell.predecessor - | Some (chain_id, _bh) -> - Lwt.return (get v chain_id) ) - | Some chain_id -> ( - Lwt.return (get v chain_id) - >>=? fun nv -> - if force then return nv - else - Distributed_db.Block_header.known - (Chain_validator.chain_db nv) - block.shell.predecessor - >>= function - | true -> - return nv - | false -> - failwith - "Unknown predecessor (%a), cannot inject the block." - Block_hash.pp_short - block.shell.predecessor ) ) - >>=? fun nv -> - let validation = - Chain_validator.validate_block nv ~force hash block operations - in - return (hash, validation) + block.shell.predecessor ) ) + >>=? fun nv -> + let validation = + Chain_validator.validate_block nv ~force hash block operations + in + return (hash, validation) let shutdown {active_chains; block_validator; _} = let chain_validator_jobs = diff --git a/src/lib_shell_services/validation_errors.ml b/src/lib_shell_services/validation_errors.ml index 57cff413db8f..69d319fde2c6 100644 --- a/src/lib_shell_services/validation_errors.ml +++ b/src/lib_shell_services/validation_errors.ml @@ -87,7 +87,7 @@ let () = ~pp:(fun ppf (block, block_time, time) -> Format.fprintf ppf - "Future block header (block: %a, block_time: %a, time: %a)" + "Received a block (%a) in the future: Current time: %a, Block time: %a." Block_hash.pp block Time.System.pp_hum -- GitLab From 21511cf3443d4eb4f880176af123b679ed5c68ac Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 21 Jan 2021 10:10:08 +0100 Subject: [PATCH 02/20] tezt/lib: add RPC and sapling command --- tezt/lib_tezos/RPC.ml | 4 + tezt/lib_tezos/RPC.mli | 9 +++ tezt/lib_tezos/client.ml | 163 ++++++++++++++++++++++++++++++++++++++ tezt/lib_tezos/client.mli | 159 ++++++++++++++++++++++++++++++++++++- 4 files changed, 334 insertions(+), 1 deletion(-) diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index ef48542ef60c..24cf2ac54b0a 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -71,6 +71,10 @@ let inject_block ?node ?hooks ~data client = let path = ["injection"; "block"] in Client.rpc ?node ?hooks ~data POST path client +let get_metadata ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "metadata"] in + Client.rpc ?node ?hooks GET path client + module Proto_alpha = struct let get_constants ?node ?hooks ?(chain = "main") ?(block = "head") client = let path = ["chains"; chain; "blocks"; block; "context"; "constants"] in diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 7be333cc6174..7406b5c16e19 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -162,6 +162,15 @@ module Proto_alpha : sig Client.t -> JSON.t Lwt.t + (** Call RPC /chain/[chain]/blocks/[block]/metadata *) + val get_metadata : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + module Contract : sig (** Call RPC /chain/[chain]/blocks/[block]/context/contracts *) val get_all : diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 7e24ae213808..0165dd32f382 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -518,6 +518,169 @@ let spawn_migrate_mockup ~next_protocol client = let migrate_mockup ~next_protocol client = spawn_migrate_mockup ~next_protocol client |> Process.check +let spawn_sapling_generate_key ?node ?(unencrypted = false) ?(force = false) + ~name client = + spawn_command + ?node + client + ( ["sapling"; "gen"; "key"; name] + @ (if unencrypted then ["--unencrypted"] else []) + @ if force then ["--force"] else [] ) + +let sapling_generate_key ?node ?unencrypted ?force ~name client = + spawn_sapling_generate_key ?node ?unencrypted ?force ~name client + |> Process.check + +let spawn_sapling_use_key ?node ?memo_size ~account ~contract client = + spawn_command + ?node + client + ( ["sapling"; "use"; "key"; account; "for"; "contract"; contract] + @ Option.fold + ~none:[] + ~some:(fun size -> ["--memo-size"; string_of_int size]) + memo_size ) + +let sapling_use_key ?node ?memo_size ~account ~contract client = + spawn_sapling_use_key ?node ?memo_size ~account ~contract client + |> Process.check + +let spawn_sapling_generate_address ?node ~account client = + spawn_command ?node client ["sapling"; "gen"; "address"; account] + +let sapling_generate_address ?node ~account client = + spawn_sapling_generate_address ?node ~account client |> Process.check + +let spawn_sapling_shield ?node ?(wait = "none") ?burn_cap ~amount ~source + ~target ~contract client = + spawn_command + ?node + client + ( ["--wait"; wait] + @ [ "sapling"; + "shield"; + string_of_int amount; + "from"; + source; + "to"; + target; + "using"; + contract ] + @ Option.fold + ~none:[] + ~some:(fun burn_cap -> ["--burn-cap"; string_of_int burn_cap]) + burn_cap ) + +let sapling_shield ?node ?wait ?burn_cap ~amount ~source ~target ~contract + client = + spawn_sapling_shield + ?node + ?wait + ?burn_cap + ~source + ~amount + ~target + ~contract + client + |> Process.check + +let spawn_sapling_unshield ?node ?(wait = "none") ?burn_cap ~amount ~source + ~target ~contract client = + spawn_command + ?node + client + ( ["--wait"; wait] + @ [ "sapling"; + "unshield"; + string_of_int amount; + "from"; + source; + "to"; + target; + "using"; + contract ] + @ Option.fold + ~none:[] + ~some:(fun burn_cap -> ["--burn-cap"; string_of_int burn_cap]) + burn_cap ) + +let sapling_unshield ?node ?wait ?burn_cap ~amount ~source ~target ~contract + client = + spawn_sapling_unshield + ?node + ?wait + ?burn_cap + ~source + ~amount + ~target + ~contract + client + |> Process.check + +let spawn_sapling_get_balance ?node ~account ~contract client = + spawn_command + ?node + client + ["sapling"; "get"; "balance"; "for"; account; "in"; "contract"; contract] + +let sapling_get_balance ?node ~account ~contract client = + spawn_sapling_get_balance ?node ~account ~contract client |> Process.check + +let spawn_sapling_forge_transaction ?node ~amount ~source ~target ~contract + client = + spawn_command + ?node + client + [ "sapling"; + "forge"; + "transaction"; + string_of_int amount; + "from"; + source; + "to"; + target; + "using"; + contract ] + +let sapling_forge_transaction ?node ~amount ~source ~target ~contract client = + spawn_sapling_forge_transaction + ?node + ~amount + ~source + ~target + ~contract + client + |> Process.check + +let spawn_sapling_submit_transaction ?node ?(wait = "none") ?burn_cap ~account + ~contract client = + spawn_command + ?node + client + ( ["--wait"; wait] + @ [ "sapling"; + "submit"; + "sapling_transaction"; + "from"; + account; + "using"; + contract ] + @ Option.fold + ~none:[] + ~some:(fun burn_cap -> ["--burn-cap"; string_of_int burn_cap]) + burn_cap ) + +let sapling_submit_transaction ?node ?wait ?burn_cap ~account ~contract client + = + spawn_sapling_submit_transaction + ?node + ?wait + ?burn_cap + ~account + ~contract + client + |> Process.check + let init ?path ?admin_path ?name ?color ?base_dir ?node () = let client = create ?path ?admin_path ?name ?color ?base_dir ?node () in let* () = diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 2e61105c9379..67af70182acf 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -336,7 +336,9 @@ val spawn_submit_ballot : ?key:string -> ?wait:string -> proto_hash:string -> ballot -> t -> Process.t (** Run [tezos-client originate contract alias transferring amount from src - running prg]. Returns the originated contract hash *) + running prg]. Returns the originated contract hash. + + Default [wait] is "none". *) val originate_contract : ?node:Node.t -> ?wait:string -> @@ -393,6 +395,161 @@ val migrate_mockup : next_protocol:Protocol.t -> t -> unit Lwt.t (** Same as [migrate_mockup], but do not wait for the process to exit. *) val spawn_migrate_mockup : next_protocol:Protocol.t -> t -> Process.t +(** Run [tezos-client sapling gen key name]. + + Default [unencrypted] is false and default [force] is false. *) +val sapling_generate_key : + ?node:Node.t -> + ?unencrypted:bool -> + ?force:bool -> + name:string -> + t -> + unit Lwt.t + +(** Same as [sapling_generate_key], but do not wait for the process to exit. *) +val spawn_sapling_generate_key : + ?node:Node.t -> + ?unencrypted:bool -> + ?force:bool -> + name:string -> + t -> + Process.t + +(** Run [tezos-client sapling use key account for contract contract]. *) +val sapling_use_key : + ?node:Node.t -> + ?memo_size:int -> + account:string -> + contract:string -> + t -> + unit Lwt.t + +(** Same as [sapling_use_key], but do not wait for the process to exit. *) +val spawn_sapling_use_key : + ?node:Node.t -> + ?memo_size:int -> + account:string -> + contract:string -> + t -> + Process.t + +(** Run [tezos-client gen address account]. *) +val sapling_generate_address : + ?node:Node.t -> account:string -> t -> unit Lwt.t + +(** Same as [sapling_generate_address], but do not wait for the process to + exit. *) +val spawn_sapling_generate_address : + ?node:Node.t -> account:string -> t -> Tezt.Process.t + +(** Run [tezos-client sapling shield amount from source to target using + contract]. + + Default [wait] is "none". *) +val sapling_shield : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + unit Lwt.t + +(** Same as [sapling_shield], but do not wait for the process to exit. *) +val spawn_sapling_shield : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + Process.t + +(** Run [tezos-client sapling unshield amount from source to target using + contract]. + + Default [wait] is "none". *) +val sapling_unshield : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + unit Lwt.t + +(** Same as [sapling_unshield], but do not wait for the process to exit. *) +val spawn_sapling_unshield : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + Process.t + +(** Run [tezos-client get balance for account in contract contract].*) +val sapling_get_balance : + ?node:Node.t -> account:string -> contract:string -> t -> unit Lwt.t + +(** Same as [sapling_get_balance], but do not wait for the process to exit. *) +val spawn_sapling_get_balance : + ?node:Node.t -> account:string -> contract:string -> t -> Process.t + +(** Run [tezos-client forge transaction amount from source to target using + contract]. *) +val sapling_forge_transaction : + ?node:Node.t -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + unit Lwt.t + +(** Same as [sapling_forge_transaction], but do not wait for the process to + exit. *) +val spawn_sapling_forge_transaction : + ?node:Node.t -> + amount:int -> + source:string -> + target:string -> + contract:string -> + t -> + Process.t + +(** Run [tezos-client sapling submit sapling_transaction from account using + contract]. + + Default [wait] is "none". *) +val sapling_submit_transaction : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + account:string -> + contract:string -> + t -> + unit Lwt.t + +(** Same as [sapling_submit_transaction], but do not wait for the process to + exit. *) +val spawn_sapling_submit_transaction : + ?node:Node.t -> + ?wait:string -> + ?burn_cap:int -> + account:string -> + contract:string -> + t -> + Process.t + (** {2 High-Level Functions} *) (** Create a client with mode [Client] and import all secret keys -- GitLab From 0556426cfd482c96147d33045313c40bc68ac280 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 20 Jan 2021 18:22:37 +0100 Subject: [PATCH 03/20] tezt/RPC: rename module RPC 007 -> 007_delphi --- tezt/lib_tezos/RPC.ml | 2 +- tezt/lib_tezos/RPC.mli | 2 +- tezt/tests/RPC_test.ml | 165 +++++++++++++++++++++++++---------------- 3 files changed, 104 insertions(+), 65 deletions(-) diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 24cf2ac54b0a..634d38e90db8 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -415,7 +415,7 @@ module Proto_alpha = struct end end -module Proto_007 = struct +module Proto_007_delphi = struct let get_constants ?node ?hooks ?(chain = "main") ?(block = "head") client = let path = ["chains"; chain; "blocks"; block; "context"; "constants"] in Client.rpc ?node ?hooks GET path client diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 7406b5c16e19..b0c75cae6bbe 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -686,7 +686,7 @@ module Proto_alpha : sig end end -module Proto_007 : sig +module Proto_007_delphi : sig (** Call RPC /chain/[chain]/blocks/[block]/context/constants *) val get_constants : ?node:Node.t -> diff --git a/tezt/tests/RPC_test.ml b/tezt/tests/RPC_test.ml index ce5c9ebc3d5e..1ddacd01e6d6 100644 --- a/tezt/tests/RPC_test.ml +++ b/tezt/tests/RPC_test.ml @@ -257,26 +257,36 @@ let test_contracts_alpha client = (* Test the contracts RPC for protocol 007. *) let test_contracts_007 client = let test_implicit_contract contract_id = - let* _ = RPC.Proto_007.Contract.get ~hooks ~contract_id client in - let* _ = RPC.Proto_007.Contract.get_balance ~hooks ~contract_id client in - let* _ = RPC.Proto_007.Contract.get_counter ~hooks ~contract_id client in + let* _ = RPC.Proto_007_delphi.Contract.get ~hooks ~contract_id client in let* _ = - RPC.Proto_007.Contract.get_manager_key ~hooks ~contract_id client + RPC.Proto_007_delphi.Contract.get_balance ~hooks ~contract_id client + in + let* _ = + RPC.Proto_007_delphi.Contract.get_counter ~hooks ~contract_id client + in + let* _ = + RPC.Proto_007_delphi.Contract.get_manager_key ~hooks ~contract_id client in unit in - let* contracts = RPC.Proto_007.Contract.get_all ~hooks client in + let* contracts = RPC.Proto_007_delphi.Contract.get_all ~hooks client in Log.info "Test implicit baker contract" ; let bootstrap = List.hd contracts in let* () = test_implicit_contract bootstrap in let* _ = - RPC.Proto_007.Contract.get_delegate ~hooks ~contract_id:bootstrap client + RPC.Proto_007_delphi.Contract.get_delegate + ~hooks + ~contract_id:bootstrap + client in Log.info "Test un-allocated implicit contract" ; let unallocated_implicit = "tz1c5BVkpwCiaPHJBzyjg7UHpJEMPTYA1bHG" in assert (not @@ List.mem unallocated_implicit contracts) ; let* _ = - RPC.Proto_007.Contract.get ~hooks ~contract_id:unallocated_implicit client + RPC.Proto_007_delphi.Contract.get + ~hooks + ~contract_id:unallocated_implicit + client in Log.info "Test non-delegated implicit contract" ; let simple_implicit = "simple" in @@ -305,10 +315,10 @@ let test_contracts_007 client = ~contract_id:simple_implicit_key.public_key_hash client |> Process.check ~expect_failure:true) - [ RPC.Proto_007.Contract.spawn_get_delegate; - RPC.Proto_007.Contract.spawn_get_entrypoints; - RPC.Proto_007.Contract.spawn_get_script; - RPC.Proto_007.Contract.spawn_get_storage ] + [ RPC.Proto_007_delphi.Contract.spawn_get_delegate; + RPC.Proto_007_delphi.Contract.spawn_get_entrypoints; + RPC.Proto_007_delphi.Contract.spawn_get_script; + RPC.Proto_007_delphi.Contract.spawn_get_storage ] in Log.info "Test delegated implicit contract" ; let delegated_implicit = "delegated" in @@ -330,7 +340,7 @@ let test_contracts_007 client = let* () = Client.bake_for client in let* () = test_implicit_contract delegated_implicit_key.public_key_hash in let* _ = - RPC.Proto_007.Contract.get_delegate + RPC.Proto_007_delphi.Contract.get_delegate ~hooks ~contract_id:delegated_implicit_key.public_key_hash client @@ -346,19 +356,27 @@ let test_contracts_007 client = ~contract_id:delegated_implicit_key.public_key_hash client |> Process.check ~expect_failure:true) - [ RPC.Proto_007.Contract.spawn_get_entrypoints; - RPC.Proto_007.Contract.spawn_get_script; - RPC.Proto_007.Contract.spawn_get_storage ] + [ RPC.Proto_007_delphi.Contract.spawn_get_entrypoints; + RPC.Proto_007_delphi.Contract.spawn_get_script; + RPC.Proto_007_delphi.Contract.spawn_get_storage ] in let test_originated_contract contract_id = - let* _ = RPC.Proto_007.Contract.get ~hooks ~contract_id client in - let* _ = RPC.Proto_007.Contract.get_balance ~hooks ~contract_id client in + let* _ = RPC.Proto_007_delphi.Contract.get ~hooks ~contract_id client in + let* _ = + RPC.Proto_007_delphi.Contract.get_balance ~hooks ~contract_id client + in let* () = - RPC.Proto_007.Contract.spawn_get_counter ~hooks ~contract_id client + RPC.Proto_007_delphi.Contract.spawn_get_counter + ~hooks + ~contract_id + client |> Process.check ~expect_failure:true in let* () = - RPC.Proto_007.Contract.spawn_get_manager_key ~hooks ~contract_id client + RPC.Proto_007_delphi.Contract.spawn_get_manager_key + ~hooks + ~contract_id + client |> Process.check ~expect_failure:true in let big_map_key = @@ -366,17 +384,21 @@ let test_contracts_007 client = "{ \"key\": { \"int\": \"0\" }, \"type\": { \"prim\": \"int\" } }" in let* _ = - RPC.Proto_007.Contract.big_map_get + RPC.Proto_007_delphi.Contract.big_map_get ~hooks ~contract_id ~data:big_map_key client in let* _ = - RPC.Proto_007.Contract.get_entrypoints ~hooks ~contract_id client + RPC.Proto_007_delphi.Contract.get_entrypoints ~hooks ~contract_id client + in + let* _ = + RPC.Proto_007_delphi.Contract.get_script ~hooks ~contract_id client + in + let* _ = + RPC.Proto_007_delphi.Contract.get_storage ~hooks ~contract_id client in - let* _ = RPC.Proto_007.Contract.get_script ~hooks ~contract_id client in - let* _ = RPC.Proto_007.Contract.get_storage ~hooks ~contract_id client in unit in (* A smart contract without any big map or entrypoints *) @@ -411,7 +433,7 @@ let test_contracts_007 client = } }" in let* _ = - RPC.Proto_007.Contract.big_map_get + RPC.Proto_007_delphi.Contract.big_map_get ~hooks ~contract_id:originated_contract_advanced ~data:unique_big_map_key @@ -422,7 +444,7 @@ let test_contracts_007 client = "{ \"key\": { \"string\": \"dup\" }, \"type\": { \"prim\": \"string\" } }" in let* _ = - RPC.Proto_007.Contract.big_map_get + RPC.Proto_007_delphi.Contract.big_map_get ~hooks ~contract_id:originated_contract_advanced ~data:duplicate_big_map_key @@ -535,89 +557,106 @@ let test_delegates_alpha client = (* Test the delegates RPC for protocol 007. *) let test_delegates_007 client = - let* contracts = RPC.Proto_007.Contract.get_all client in + let* contracts = RPC.Proto_007_delphi.Contract.get_all client in Log.info "Test implicit baker contract" ; let bootstrap = List.hd contracts in - let* _ = RPC.Proto_007.Delegate.get ~hooks ~pkh:bootstrap client in - let* _ = RPC.Proto_007.Delegate.get_balance ~hooks ~pkh:bootstrap client in + let* _ = RPC.Proto_007_delphi.Delegate.get ~hooks ~pkh:bootstrap client in let* _ = - RPC.Proto_007.Delegate.get_deactivated ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_balance ~hooks ~pkh:bootstrap client in let* _ = - RPC.Proto_007.Delegate.get_delegated_balance ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_deactivated ~hooks ~pkh:bootstrap client in let* _ = - RPC.Proto_007.Delegate.get_delegated_contracts ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_delegated_balance + ~hooks + ~pkh:bootstrap + client in let* _ = - RPC.Proto_007.Delegate.get_frozen_balance ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_delegated_contracts + ~hooks + ~pkh:bootstrap + client in let* _ = - RPC.Proto_007.Delegate.get_frozen_balance_by_cycle + RPC.Proto_007_delphi.Delegate.get_frozen_balance ~hooks ~pkh:bootstrap client in let* _ = - RPC.Proto_007.Delegate.get_grace_period ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_frozen_balance_by_cycle + ~hooks + ~pkh:bootstrap + client in let* _ = - RPC.Proto_007.Delegate.get_staking_balance ~hooks ~pkh:bootstrap client + RPC.Proto_007_delphi.Delegate.get_grace_period ~hooks ~pkh:bootstrap client + in + let* _ = + RPC.Proto_007_delphi.Delegate.get_staking_balance + ~hooks + ~pkh:bootstrap + client in Log.info "Test with a PKH that is not a registered baker contract" ; let unregistered_baker = "tz1c5BVkpwCiaPHJBzyjg7UHpJEMPTYA1bHG" in assert (not @@ List.mem unregistered_baker contracts) ; let* _ = - RPC.Proto_007.Delegate.spawn_get ~hooks ~pkh:unregistered_baker client + RPC.Proto_007_delphi.Delegate.spawn_get + ~hooks + ~pkh:unregistered_baker + client |> Process.check ~expect_failure:true in let* _ = - RPC.Proto_007.Delegate.spawn_get_balance + RPC.Proto_007_delphi.Delegate.spawn_get_balance ~hooks ~pkh:unregistered_baker client |> Process.check ~expect_failure:true in let* _ = - RPC.Proto_007.Delegate.get_deactivated + RPC.Proto_007_delphi.Delegate.get_deactivated ~hooks ~pkh:unregistered_baker client in let* _ = - RPC.Proto_007.Delegate.spawn_get_delegated_balance + RPC.Proto_007_delphi.Delegate.spawn_get_delegated_balance ~hooks ~pkh:unregistered_baker client |> Process.check ~expect_failure:true in let* _ = - RPC.Proto_007.Delegate.get_delegated_contracts + RPC.Proto_007_delphi.Delegate.get_delegated_contracts ~hooks ~pkh:unregistered_baker client in let* _ = - RPC.Proto_007.Delegate.get_frozen_balance + RPC.Proto_007_delphi.Delegate.get_frozen_balance ~hooks ~pkh:unregistered_baker client in let* _ = - RPC.Proto_007.Delegate.get_frozen_balance_by_cycle + RPC.Proto_007_delphi.Delegate.get_frozen_balance_by_cycle ~hooks ~pkh:unregistered_baker client in let* _ = - RPC.Proto_007.Delegate.spawn_get_grace_period + RPC.Proto_007_delphi.Delegate.spawn_get_grace_period ~hooks ~pkh:unregistered_baker client |> Process.check ~expect_failure:true in let* _ = - RPC.Proto_007.Delegate.get_staking_balance + RPC.Proto_007_delphi.Delegate.get_staking_balance ~hooks ~pkh:unregistered_baker client @@ -669,13 +708,13 @@ let test_votes_007 client = let* () = Client.submit_proposals ~proto_hash client in let* () = Client.bake_for client in (* RPC calls *) - let* _ = RPC.Proto_007.Votes.get_ballot_list ~hooks client in - let* _ = RPC.Proto_007.Votes.get_ballots ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_period_kind ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_proposal ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_quorum ~hooks client in - let* _ = RPC.Proto_007.Votes.get_listings ~hooks client in - let* _ = RPC.Proto_007.Votes.get_proposals ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_ballot_list ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_ballots ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_period_kind ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_proposal ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_quorum ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_listings ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_proposals ~hooks client in (* bake to testing vote period and submit some ballots *) let* () = Client.bake_for client in let* () = Client.bake_for client in @@ -684,13 +723,13 @@ let test_votes_007 client = let* () = Client.submit_ballot ~key:"bootstrap3" ~proto_hash Pass client in let* () = Client.bake_for client in (* RPC calls again *) - let* _ = RPC.Proto_007.Votes.get_ballot_list ~hooks client in - let* _ = RPC.Proto_007.Votes.get_ballots ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_period_kind ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_proposal ~hooks client in - let* _ = RPC.Proto_007.Votes.get_current_quorum ~hooks client in - let* _ = RPC.Proto_007.Votes.get_listings ~hooks client in - let* _ = RPC.Proto_007.Votes.get_proposals ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_ballot_list ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_ballots ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_period_kind ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_proposal ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_current_quorum ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_listings ~hooks client in + let* _ = RPC.Proto_007_delphi.Votes.get_proposals ~hooks client in unit (* Test the various other RPCs for protocol Alpha. *) @@ -704,11 +743,11 @@ let test_others_alpha client = (* Test the various other RPCs for protocol 007. *) let test_others_007 client = - let* _ = RPC.Proto_007.get_constants ~hooks client in - let* _ = RPC.Proto_007.get_baking_rights ~hooks client in - let* _ = RPC.Proto_007.get_current_level ~hooks client in - let* _ = RPC.Proto_007.get_endorsing_rights ~hooks client in - let* _ = RPC.Proto_007.get_levels_in_current_cycle ~hooks client in + let* _ = RPC.Proto_007_delphi.get_constants ~hooks client in + let* _ = RPC.Proto_007_delphi.get_baking_rights ~hooks client in + let* _ = RPC.Proto_007_delphi.get_current_level ~hooks client in + let* _ = RPC.Proto_007_delphi.get_endorsing_rights ~hooks client in + let* _ = RPC.Proto_007_delphi.get_levels_in_current_cycle ~hooks client in unit let register () = -- GitLab From d3abfd7daa3349b5390055bc5eeb666a89833c6a Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 21 Jan 2021 10:01:10 +0100 Subject: [PATCH 04/20] tezt/lib: add 008 RPC --- tezt/lib_tezos/RPC.ml | 340 ++++++++++++++++++++++++ tezt/lib_tezos/RPC.mli | 591 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 922 insertions(+), 9 deletions(-) diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 634d38e90db8..b42bd0df8890 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -415,6 +415,346 @@ module Proto_alpha = struct end end +module Proto_008_edo = struct + let get_constants ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "context"; "constants"] in + Client.rpc ?node ?hooks GET path client + + let get_constants_errors ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = + ["chains"; chain; "blocks"; block; "context"; "constants"; "errors"] + in + Client.rpc ?node ?hooks GET path client + + let get_baking_rights ?node ?hooks ?(chain = "main") ?(block = "head") + ?delegate client = + let path = + ["chains"; chain; "blocks"; block; "helpers"; "baking_rights"] + in + let query_string = Option.map (fun d -> [("delegate", d)]) delegate in + Client.rpc ?node ?hooks ?query_string GET path client + + let get_current_level ?node ?hooks ?(chain = "main") ?(block = "head") + ?(offset = 0) client = + let path = + ["chains"; chain; "blocks"; block; "helpers"; "current_level"] + in + let query_string = [("offset", string_of_int offset)] in + Client.rpc ?node ?hooks ~query_string GET path client + + let get_endorsing_rights ?node ?hooks ?(chain = "main") ?(block = "head") + ?delegate client = + let path = + ["chains"; chain; "blocks"; block; "helpers"; "endorsing_rights"] + in + let query_string = Option.map (fun d -> [("delegate", d)]) delegate in + Client.rpc ?node ?hooks ?query_string GET path client + + let get_levels_in_current_cycle ?node ?hooks ?(chain = "main") + ?(block = "head") client = + let path = + ["chains"; chain; "blocks"; block; "helpers"; "levels_in_current_cycle"] + in + Client.rpc ?node ?hooks GET path client + + module Contract = struct + let spawn_get_all ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "context"; "contracts"] in + Client.spawn_rpc ?node ?hooks GET path client + + let get_all ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "context"; "contracts"] in + let* contracts = Client.rpc ?node ?hooks GET path client in + return (JSON.as_list contracts |> List.map JSON.as_string) + + let spawn_get ?node ?hooks ?(chain = "main") ?(block = "head") ~contract_id + client = + let path = + ["chains"; chain; "blocks"; block; "context"; "contracts"; contract_id] + in + Client.spawn_rpc ?node ?hooks GET path client + + let get ?node ?hooks ?(chain = "main") ?(block = "head") ~contract_id + client = + let path = + ["chains"; chain; "blocks"; block; "context"; "contracts"; contract_id] + in + Client.rpc ?node ?hooks GET path client + + let sub_path ~chain ~block ~contract_id field = + [ "chains"; + chain; + "blocks"; + block; + "context"; + "contracts"; + contract_id; + field ] + + let spawn_get_sub ?node ?hooks ~chain ~block ~contract_id field client = + let path = sub_path ~chain ~block ~contract_id field in + Client.spawn_rpc ?node ?hooks GET path client + + let get_sub ?node ?hooks ~chain ~block ~contract_id field client = + let path = sub_path ~chain ~block ~contract_id field in + Client.rpc ?node ?hooks GET path client + + let spawn_get_balance ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub ?node ?hooks ~chain ~block ~contract_id "balance" client + + let get_balance ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "balance" client + + let spawn_big_map_get ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id ~data client = + let path = sub_path ~chain ~block ~contract_id "big_map_get" in + Client.spawn_rpc ?node ?hooks ~data POST path client + + let big_map_get ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id ~data client = + let path = sub_path ~chain ~block ~contract_id "big_map_get" in + Client.rpc ?node ?hooks ~data POST path client + + let spawn_get_counter ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub ?node ?hooks ~chain ~block ~contract_id "counter" client + + let get_counter ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "counter" client + + let spawn_get_delegate ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub ?node ?hooks ~chain ~block ~contract_id "delegate" client + + let get_delegate ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "delegate" client + + let spawn_get_entrypoints ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub + ?node + ?hooks + ~chain + ~block + ~contract_id + "entrypoints" + client + + let get_entrypoints ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "entrypoints" client + + let spawn_get_manager_key ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub + ?node + ?hooks + ~chain + ~block + ~contract_id + "manager_key" + client + + let get_manager_key ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "manager_key" client + + let spawn_get_script ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub ?node ?hooks ~chain ~block ~contract_id "script" client + + let get_script ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "script" client + + let spawn_get_storage ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + spawn_get_sub ?node ?hooks ~chain ~block ~contract_id "storage" client + + let get_storage ?node ?hooks ?(chain = "main") ?(block = "head") + ~contract_id client = + get_sub ?node ?hooks ~chain ~block ~contract_id "storage" client + end + + module Delegate = struct + let spawn_get_all ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "context"; "delegates"] in + Client.spawn_rpc ?node ?hooks GET path client + + let get_all ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = ["chains"; chain; "blocks"; block; "context"; "delegates"] in + let* contracts = Client.rpc ?node ?hooks GET path client in + return (JSON.as_list contracts |> List.map JSON.as_string) + + let spawn_get ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh client + = + let path = + ["chains"; chain; "blocks"; block; "context"; "delegates"; pkh] + in + Client.spawn_rpc ?node ?hooks GET path client + + let get ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh client = + let path = + ["chains"; chain; "blocks"; block; "context"; "delegates"; pkh] + in + Client.rpc ?node ?hooks GET path client + + let sub_path ~chain ~block ~pkh field = + ["chains"; chain; "blocks"; block; "context"; "delegates"; pkh; field] + + let spawn_get_sub ?node ?hooks ~chain ~block ~pkh field client = + let path = sub_path ~chain ~block ~pkh field in + Client.spawn_rpc ?node ?hooks GET path client + + let get_sub ?node ?hooks ~chain ~block ~pkh field client = + let path = sub_path ~chain ~block ~pkh field in + Client.rpc ?node ?hooks GET path client + + let spawn_get_balance ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh + client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "balance" client + + let get_balance ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh + client = + get_sub ?node ?hooks ~chain ~block ~pkh "balance" client + + let spawn_get_deactivated ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "deactivated" client + + let get_deactivated ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh + client = + get_sub ?node ?hooks ~chain ~block ~pkh "deactivated" client + + let spawn_get_delegated_balance ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "delegated_balance" client + + let get_delegated_balance ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + get_sub ?node ?hooks ~chain ~block ~pkh "delegated_balance" client + + let spawn_get_delegated_contracts ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + spawn_get_sub + ?node + ?hooks + ~chain + ~block + ~pkh + "delegated_contracts" + client + + let get_delegated_contracts ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + get_sub ?node ?hooks ~chain ~block ~pkh "delegated_contracts" client + + let spawn_get_frozen_balance ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "frozen_balance" client + + let get_frozen_balance ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + get_sub ?node ?hooks ~chain ~block ~pkh "frozen_balance" client + + let spawn_get_frozen_balance_by_cycle ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + spawn_get_sub + ?node + ?hooks + ~chain + ~block + ~pkh + "frozen_balance_by_cycle" + client + + let get_frozen_balance_by_cycle ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + get_sub ?node ?hooks ~chain ~block ~pkh "frozen_balance_by_cycle" client + + let spawn_get_grace_period ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "grace_period" client + + let get_grace_period ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh + client = + get_sub ?node ?hooks ~chain ~block ~pkh "grace_period" client + + let spawn_get_staking_balance ?node ?hooks ?(chain = "main") + ?(block = "head") ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "staking_balance" client + + let get_staking_balance ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + get_sub ?node ?hooks ~chain ~block ~pkh "staking_balance" client + + let spawn_get_voting_power ?node ?hooks ?(chain = "main") ?(block = "head") + ~pkh client = + spawn_get_sub ?node ?hooks ~chain ~block ~pkh "voting_power" client + + let get_voting_power ?node ?hooks ?(chain = "main") ?(block = "head") ~pkh + client = + get_sub ?node ?hooks ~chain ~block ~pkh "voting_power" client + end + + module Votes = struct + let sub_path ~chain ~block sub = + ["chains"; chain; "blocks"; block; "votes"; sub] + + let get_ballot_list ?node ?hooks ?(chain = "main") ?(block = "head") client + = + let path = sub_path ~chain ~block "ballot_list" in + Client.rpc ?node ?hooks GET path client + + let get_ballots ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = sub_path ~chain ~block "ballots" in + Client.rpc ?node ?hooks GET path client + + let get_current_period ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = sub_path ~chain ~block "current_period" in + Client.rpc ?node ?hooks GET path client + + let get_successor_period ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = sub_path ~chain ~block "successor_period" in + Client.rpc ?node ?hooks GET path client + + let get_current_period_kind ?node ?hooks ?(chain = "main") + ?(block = "head") client = + let path = sub_path ~chain ~block "current_period_kind" in + Client.rpc ?node ?hooks GET path client + + let get_current_proposal ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = sub_path ~chain ~block "current_proposal" in + Client.rpc ?node ?hooks GET path client + + let get_current_quorum ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = sub_path ~chain ~block "current_quorum" in + Client.rpc ?node ?hooks GET path client + + let get_listings ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = sub_path ~chain ~block "listings" in + Client.rpc ?node ?hooks GET path client + + let get_proposals ?node ?hooks ?(chain = "main") ?(block = "head") client = + let path = sub_path ~chain ~block "proposals" in + Client.rpc ?node ?hooks GET path client + + let get_total_voting_power ?node ?hooks ?(chain = "main") ?(block = "head") + client = + let path = sub_path ~chain ~block "total_voting_power" in + Client.rpc ?node ?hooks GET path client + end +end + module Proto_007_delphi = struct let get_constants ?node ?hooks ?(chain = "main") ?(block = "head") client = let path = ["chains"; chain; "blocks"; block; "context"; "constants"] in diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index b0c75cae6bbe..01b7497b3627 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -104,6 +104,15 @@ val preapply_block : Client.t -> JSON.t Lwt.t +(** Call RPC /chain/[chain]/blocks/[block]/metadata *) +val get_metadata : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + module Proto_alpha : sig (** Call RPC /chain/[chain]/blocks/[block]/context/constants *) val get_constants : @@ -162,15 +171,6 @@ module Proto_alpha : sig Client.t -> JSON.t Lwt.t - (** Call RPC /chain/[chain]/blocks/[block]/metadata *) - val get_metadata : - ?node:Node.t -> - ?hooks:Process.hooks -> - ?chain:string -> - ?block:string -> - Client.t -> - JSON.t Lwt.t - module Contract : sig (** Call RPC /chain/[chain]/blocks/[block]/context/contracts *) val get_all : @@ -686,6 +686,579 @@ module Proto_alpha : sig end end +module Proto_008_edo : sig + (** Call RPC /chain/[chain]/blocks/[block]/context/constants *) + val get_constants : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/constants/errors *) + val get_constants_errors : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/helpers/baking_rights *) + val get_baking_rights : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + ?delegate:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/helpers/current_level *) + val get_current_level : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + ?offset:int -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/helpers/endorsing_rights *) + val get_endorsing_rights : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + ?delegate:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/helpers/levels_in_current_cycle *) + val get_levels_in_current_cycle : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + module Contract : sig + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts *) + val get_all : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + string list Lwt.t + + (** Same as [get_all], but do not wait for the process to exit. *) + val spawn_get_all : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id] *) + val get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get], but do not wait for the process to exit. *) + val spawn_get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/balance *) + val get_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_balance], but do not wait for the process to exit. *) + val spawn_get_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/big_map_get *) + val big_map_get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + data:JSON.u -> + Client.t -> + JSON.t Lwt.t + + (** Same as [big_map_get], but do not wait for the process to exit. *) + val spawn_big_map_get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + data:JSON.u -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/counter *) + val get_counter : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_counter], but do not wait for the process to exit. *) + val spawn_get_counter : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/delegate *) + val get_delegate : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_delegate], but do not wait for the process to exit. *) + val spawn_get_delegate : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/entrypoints *) + val get_entrypoints : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_entrypoints], but do not wait for the process to exit. *) + val spawn_get_entrypoints : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/manager_key *) + val get_manager_key : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_manager_key], but do not wait for the process to exit. *) + val spawn_get_manager_key : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/script *) + val get_script : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_script], but do not wait for the process to exit. *) + val spawn_get_script : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/contracts/[contract_id]/storage *) + val get_storage : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_storage], but do not wait for the process to exit. *) + val spawn_get_storage : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + contract_id:string -> + Client.t -> + Process.t + end + + module Delegate : sig + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates *) + val get_all : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + string list Lwt.t + + (** Same as [get_all], but do not wait for the process to exit. *) + val spawn_get_all : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh] *) + val get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get], but do not wait for the process to exit. *) + val spawn_get : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/balance *) + val get_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_balance], but do not wait for the process to exit. *) + val spawn_get_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/deactivated *) + val get_deactivated : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_deactivated], but do not wait for the process to exit. *) + val spawn_get_deactivated : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/delegated_balance *) + val get_delegated_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_delegated_balance], but do not wait for the process to exit. *) + val spawn_get_delegated_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/delegated_contracts *) + val get_delegated_contracts : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_delegated_contracts], but do not wait for the process to exit. *) + val spawn_get_delegated_contracts : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/frozen_balance *) + val get_frozen_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_frozen_balance], but do not wait for the process to exit. *) + val spawn_get_frozen_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/frozen_balance_by_cycle *) + val get_frozen_balance_by_cycle : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_frozen_balance_by_cycle], but do not wait for the process to exit. *) + val spawn_get_frozen_balance_by_cycle : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/grace_period *) + val get_grace_period : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_grace_period], but do not wait for the process to exit. *) + val spawn_get_grace_period : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/staking_balance *) + val get_staking_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_staking_balance], but do not wait for the process to exit. *) + val spawn_get_staking_balance : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + + (** Call RPC /chain/[chain]/blocks/[block]/context/delegates/[pkh]/voting_power *) + val get_voting_power : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + JSON.t Lwt.t + + (** Same as [get_voting_power], but do not wait for the process to exit. *) + val spawn_get_voting_power : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + pkh:string -> + Client.t -> + Process.t + end + + module Votes : sig + (** Call RPC /chain/[chain]/blocks/[block]/votes/ballot_list *) + val get_ballot_list : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/ballots *) + val get_ballots : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/current_period *) + val get_current_period : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/successor_period *) + val get_successor_period : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/current_period_kind *) + val get_current_period_kind : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/current_proposal *) + val get_current_proposal : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/current_quorum *) + val get_current_quorum : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/listings *) + val get_listings : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/proposals *) + val get_proposals : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + + (** Call RPC /chain/[chain]/blocks/[block]/votes/total_voting_power *) + val get_total_voting_power : + ?node:Node.t -> + ?hooks:Process.hooks -> + ?chain:string -> + ?block:string -> + Client.t -> + JSON.t Lwt.t + end +end + module Proto_007_delphi : sig (** Call RPC /chain/[chain]/blocks/[block]/context/constants *) val get_constants : -- GitLab From caf1d025797ab9f00966ffd9518f1b2944c225fe Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Wed, 25 Nov 2020 11:08:29 +0100 Subject: [PATCH 05/20] tezt/lib: add sync_latency node argument --- tezt/lib_tezos/node.ml | 3 +++ tezt/lib_tezos/node.mli | 1 + 2 files changed, 4 insertions(+) diff --git a/tezt/lib_tezos/node.ml b/tezt/lib_tezos/node.ml index e78c78a5b594..c1ec20043ce1 100644 --- a/tezt/lib_tezos/node.ml +++ b/tezt/lib_tezos/node.ml @@ -33,6 +33,7 @@ type argument = | Bootstrap_threshold of int | Synchronisation_threshold of int | Connections of int + | Sync_latency of int | Private_mode | Peer of string @@ -55,6 +56,8 @@ let make_argument = function ["--synchronisation-threshold"; string_of_int x] | Connections x -> ["--connections"; string_of_int x] + | Sync_latency x -> + ["--sync-latency"; string_of_int x] | Private_mode -> ["--private-mode"] | Peer x -> diff --git a/tezt/lib_tezos/node.mli b/tezt/lib_tezos/node.mli index cf7664eb5dd2..abaf89e883eb 100644 --- a/tezt/lib_tezos/node.mli +++ b/tezt/lib_tezos/node.mli @@ -61,6 +61,7 @@ type argument = | Bootstrap_threshold of int (** [--bootstrap-threshold] (deprecated) *) | Synchronisation_threshold of int (** [--synchronisation-threshold] *) | Connections of int (** [--connections] *) + | Sync_latency of int (** [--sync-latency] *) | Private_mode (** [--private-mode] *) | Peer of string (** [--peer] *) -- GitLab From 122705e270b0e499fbbc14ada6d23b5abba68e05 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 3 Dec 2020 18:41:18 +0100 Subject: [PATCH 06/20] tezt/lib_tezos: add force option to client's bake_for --- tezt/lib_tezos/client.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 0165dd32f382..664866062f96 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -272,7 +272,7 @@ let activate_protocol ?node ~protocol ?fitness ?key ?timestamp ?timestamp_delay |> Process.check let spawn_bake_for ?node ?protocol ?(key = Constant.bootstrap1.alias) - ?(minimal_timestamp = true) ?mempool ?force ?context_path client = + ?(minimal_timestamp = true) ?mempool ?(force = false) ?context_path client = spawn_command ?node client @@ -286,7 +286,7 @@ let spawn_bake_for ?node ?protocol ?(key = Constant.bootstrap1.alias) ~none:[] ~some:(fun mempool_json -> ["--mempool"; mempool_json]) mempool - @ (match force with None | Some false -> [] | Some true -> ["--force"]) + @ if force then ["--force"] else [] @ Option.fold ~none:[] ~some:(fun path -> ["--context"; path]) context_path ) -- GitLab From 84b7c8e2d9aabdf3e3b67f579fcbb62959985dd3 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Mon, 7 Dec 2020 14:56:41 +0100 Subject: [PATCH 07/20] tezt/manual: rework migration test to be more modular --- tezt/manual_tests/main.ml | 2 +- tezt/manual_tests/migration_mainnet_alpha.ml | 56 +++++ .../{migration.ml => migration_utils.ml} | 233 ++++++++++++------ tezt/manual_tests/migration_utils.mli | 70 ++++++ 4 files changed, 280 insertions(+), 81 deletions(-) create mode 100644 tezt/manual_tests/migration_mainnet_alpha.ml rename tezt/manual_tests/{migration.ml => migration_utils.ml} (56%) create mode 100644 tezt/manual_tests/migration_utils.mli diff --git a/tezt/manual_tests/main.ml b/tezt/manual_tests/main.ml index 3a1cdd15ad95..c4b228770a27 100644 --- a/tezt/manual_tests/main.ml +++ b/tezt/manual_tests/main.ml @@ -28,6 +28,6 @@ as functions to be called here. *) let () = - Migration.register () ; + Migration_mainnet_alpha.register () ; (* Test.run () should be the last statement, don't register afterwards! *) Test.run () diff --git a/tezt/manual_tests/migration_mainnet_alpha.ml b/tezt/manual_tests/migration_mainnet_alpha.ml new file mode 100644 index 000000000000..4fcbd2179f25 --- /dev/null +++ b/tezt/manual_tests/migration_mainnet_alpha.ml @@ -0,0 +1,56 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Metastate AG *) +(* *) +(* 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 Migration_utils + +let mainnet_context = "~/tezos-node-test" + +let current_protocol = Protocol.Delphi + +let protocol_hash = Protocol.(hash Alpha) + +let protocol_tag = Protocol.(tag Alpha) + +let test_migration ~long = + Test.register + ~__FILE__ + ~title:"stiching test" + ~tags: + [ "node"; + "user_activated"; + "protocol"; + protocol_tag; + "migration"; + "stiching"; + (if long then "long" else "short") ] + @@ fun () -> + template_test_migration + ~migrate_at_end_of_cycle:long + ~bake_until_new_cycle:long + ~context:mainnet_context + ~current_protocol + protocol_hash + +let register () = test_migration ~long:true ; test_migration ~long:false diff --git a/tezt/manual_tests/migration.ml b/tezt/manual_tests/migration_utils.ml similarity index 56% rename from tezt/manual_tests/migration.ml rename to tezt/manual_tests/migration_utils.ml index ba04dc208636..00472ee58569 100644 --- a/tezt/manual_tests/migration.ml +++ b/tezt/manual_tests/migration_utils.ml @@ -23,39 +23,39 @@ (* *) (*****************************************************************************) -let update_config_with_user_activated config_file level protocol = - let user_activated = - Ezjsonm.( - dict - [ ( "genesis", - dict - [ ("timestamp", string "2018-06-30T16:07:32Z"); - ( "block", - string "BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2" - ); - ( "protocol", - string "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P" - ) ] ); - ("chain_name", string "TEZOS_MAINNET"); - ("old_chain_name", string "TEZOS_BETANET_2018-06-30T16:07:32Z"); - ("incompatible_chain_name", string "INCOMPATIBLE"); - ("sandboxed_chain_name", string "SANDBOXED_TEZOS_MAINNET"); - ( "user_activated_upgrades", - list - dict - [ [ ("level", int level); - ("replacement_protocol", string (Protocol.hash protocol)) ] - ] ) ]) - in - let config_json = JSON.parse_file config_file in - let config_json = - Ezjsonm.update - (JSON.unannotate config_json) - ["network"] - (Some user_activated) - in - with_open_out config_file (fun chan -> - Ezjsonm.value_to_channel ~minify:false chan config_json) +let get_current_level ~current_protocol ?node client = + match current_protocol with + | Protocol.Alpha -> + RPC.Proto_alpha.get_current_level ?node client + | Protocol.Delphi -> + RPC.Proto_007_delphi.get_current_level ?node client + | Protocol.Edo -> + RPC.Proto_008_edo.get_current_level ?node client + | _ -> + let open Protocol in + Test.fail + "wrong current protocol %s. Only %s, %s, %s are accepted protocol" + (name current_protocol) + (name Alpha) + (name Delphi) + (name Edo) + +let get_levels_in_current_cycle ~current_protocol ?node client = + match current_protocol with + | Protocol.Alpha -> + RPC.Proto_alpha.get_levels_in_current_cycle ?node client + | Protocol.Delphi -> + RPC.Proto_007_delphi.get_levels_in_current_cycle ?node client + | Protocol.Edo -> + RPC.Proto_008_edo.get_levels_in_current_cycle ?node client + | _ -> + let open Protocol in + Test.fail + "wrong current protocol %s. Only %s, %s, %s are accepted protocol" + (name current_protocol) + (name Alpha) + (name Delphi) + (name Edo) let rec bake_with_foundation ?(foundation_index = [1; 2; 3; 4; 5; 6; 7; 8]) client = @@ -66,24 +66,26 @@ let rec bake_with_foundation ?(foundation_index = [1; 2; 3; 4; 5; 6; 7; 8]) let foundation = List.nth foundation_index index in let proc = Client.spawn_bake_for + ~force:true + ~minimal_timestamp:true ~key:("foundation" ^ string_of_int foundation) client in let* res = Process.wait proc in if res != Unix.WEXITED 0 then - let* has_correct_error = + let* baker_has_no_slot = Lwt_stream.find (fun stderr_bake -> stderr_bake =~ rex "No\\sslot\\sfound\\sat\\slevel\\s[0-9]+") (Lwt_io.read_lines (Process.stderr proc)) in - if Option.is_some has_correct_error then + if Option.is_some baker_has_no_slot then let foundation_index = List.filter (( <> ) foundation) foundation_index in bake_with_foundation ~foundation_index client - else unit - else unit + else Process.check proc + else Process.check proc let create_yes_wallet () = let yes_wallet = Temp.dir "yes-wallet" in @@ -95,29 +97,78 @@ let create_yes_wallet () = json_to_file (sk_list_json alias_pkh_pk_list) (yes_wallet // "secret_keys") ; yes_wallet -(* This test checks the migration of a protocol with a context imported from a - snapshot. See the tezos online documentation to have an in-depth explanation - of that test and how to use it. The documentation can be found at this - address: https://tezos.gitlab.io/developer/proposal_testing.html *) -let migration ?yes_node_path ?yes_wallet context protocol = - Test.register - ~__FILE__ - ~title:"migration test" - ~tags:["node"; "activate"; "user_activated"; "protocol"; "migration"] - @@ fun () -> +let next_name = ref 1 + +let fresh_index () = + let index = !next_name in + incr next_name ; index + +let prepare_yes_wallet ~yes_wallet run_index = + Log.info "Creating yes-wallet dir" ; + match yes_wallet with + | Some yes_wallet -> + let base_dir = Temp.dir ("yes_wallet" ^ string_of_int run_index) in + let* () = Process.run "cp" ["-R"; yes_wallet ^ "/."; base_dir] in + Lwt.return base_dir + | None -> + Lwt.return @@ create_yes_wallet () + +let copy_context context run_index = Log.info "Copying context into a temporary directory" ; - let data_dir = Temp.dir "tezos-node-test" in + let data_dir = Temp.dir ("node" ^ string_of_int run_index) in let* () = Process.run "cp" ["-R"; context ^ "/."; data_dir] in + return data_dir + +let update_config_with_user_activated config_file level protocol = + let user_activated = + Ezjsonm.( + dict + [ ( "genesis", + dict + [ ("timestamp", string "2018-06-30T16:07:32Z"); + ( "block", + string "BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2" + ); + ( "protocol", + string "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P" + ) ] ); + ("chain_name", string "TEZOS_MAINNET"); + ("old_chain_name", string "TEZOS_BETANET_2018-06-30T16:07:32Z"); + ("incompatible_chain_name", string "INCOMPATIBLE"); + ("sandboxed_chain_name", string "SANDBOXED_TEZOS_MAINNET"); + ( "user_activated_upgrades", + list + dict + [ [ ("level", int level); + ("replacement_protocol", string protocol) ] ] ) ]) + in + let config_json = JSON.parse_file config_file in + let config_json = + Ezjsonm.update + (JSON.unannotate config_json) + ["network"] + (Some user_activated) + in + with_open_out config_file (fun chan -> + Ezjsonm.value_to_channel ~minify:false chan config_json) + +let prepare_node_and_client ?yes_node_path ?(migrate_at_end_of_cycle = false) + ~base_dir ~data_dir ~current_protocol protocol = let* node = Node.init ~rpc_port:19731 ~net_port:18731 ~data_dir [Connections 0] in let* client = Client.init ~node () in - (* Starting on protocol 007 before migration *) - let* json = RPC.Proto_007.get_current_level ~node client in + let* json = get_current_level ~current_protocol ~node client in let level = JSON.(json |-> "level" |> as_int) in + let* migration_level = + if migrate_at_end_of_cycle then + let* json = get_levels_in_current_cycle ~current_protocol client in + let last_block_of_cycle = JSON.(json |-> "last" |> as_int) in + return last_block_of_cycle + else return (level + 1) + in let* () = Node.terminate node in Log.info "Updating node config with user_activated_upgrade" ; - let migration_level = level + 1 in update_config_with_user_activated (data_dir ^ "/config.json") migration_level @@ -128,47 +179,43 @@ let migration ?yes_node_path ?yes_wallet context protocol = ~rpc_port:19731 ~net_port:18731 ~data_dir - [] + [Connections 0; Synchronisation_threshold 0; Sync_latency 65535] in - let* () = Node.run node [Connections 0] in + let* () = Node.run node [] in let* () = Node.wait_for_ready node in - Log.info "Creating yes-wallet dir" ; - let* base_dir = - match yes_wallet with - | Some yes_wallet -> - let base_dir = Temp.dir "client" in - let* () = Process.run "cp" ["-R"; yes_wallet ^ "/."; base_dir] in - Lwt.return base_dir - | None -> - Lwt.return @@ create_yes_wallet () - in let client = Client.create ~base_dir ~node () in - Log.info "Bake and wait until migration is finished" ; - let* () = bake_with_foundation client in + return (node, client, migration_level) + +let migrate node client ~migration_level ~current_protocol = + Log.info "Bake and wait until migrate is finished" ; + let* json = get_current_level ~current_protocol ~node client in + let level_level_before = JSON.(json |-> "level" |> as_int) in + let* () = + repeat (migration_level - level_level_before) (fun () -> + bake_with_foundation client) + in let* _until_mig = Node.wait_for_level node migration_level in - let (get_current_level, get_levels_in_current_cycle) = - match protocol with - | Protocol.Carthage -> - ( RPC.Proto_007.get_current_level, - RPC.Proto_007.get_levels_in_current_cycle ) - | Edo | Delphi | Alpha -> - ( RPC.Proto_alpha.get_current_level, - RPC.Proto_alpha.get_levels_in_current_cycle ) + unit + +let bake_until_next_cycle ~current_protocol node client = + let* json = get_current_level ~current_protocol ~node client in + let level_before = JSON.(json |-> "level" |> as_int) in + let* levels_in_current_cycle = + get_levels_in_current_cycle ~current_protocol ~node client in - let* levels_in_current_cycle = get_levels_in_current_cycle client in let last_block_of_cycle = JSON.(levels_in_current_cycle |-> "last" |> as_int) in - let* prev_level = get_current_level client in + let* prev_level = get_current_level ~current_protocol ~node client in let prev_cycle = JSON.(prev_level |-> "cycle" |> as_int) in Log.info "Bake until new cycle" ; let* () = repeat - (last_block_of_cycle - migration_level + 1) + (last_block_of_cycle - level_before + 1) (fun () -> bake_with_foundation client) in let* _until_end_of_cycle = Node.wait_for_level node last_block_of_cycle in - let* after_level = get_current_level client in + let* after_level = get_current_level ~current_protocol ~node client in let after_cycle = JSON.(after_level |-> "cycle" |> as_int) in if prev_cycle + 1 <> after_cycle then Test.fail @@ -177,8 +224,34 @@ let migration ?yes_node_path ?yes_wallet context protocol = after_cycle else unit -let protocol = Protocol.Alpha +type 'a get_prior_value = Node.t -> Client.t -> 'a Lwt.t -let context = "~/tezos-node-test" +type 'a migration_test = Node.t -> Client.t -> 'a -> unit Lwt.t -let register () = migration context protocol +let template_test_migration ?yes_node_path ?yes_wallet ?migrate_at_end_of_cycle + ?(bake_until_new_cycle = false) ?specific_test ~context ~current_protocol + protocol_hash = + let run_index = fresh_index () in + let* data_dir = copy_context context run_index in + let* base_dir = prepare_yes_wallet ~yes_wallet run_index in + let* (node, client, migration_level) = + prepare_node_and_client + ?yes_node_path + ?migrate_at_end_of_cycle + ~data_dir + ~base_dir + ~current_protocol + protocol_hash + in + let* () = + match specific_test with + | Some (get_prior_value, test) -> + let* prior_value = get_prior_value node client in + let* () = migrate ~current_protocol node client ~migration_level in + test node client prior_value + | None -> + migrate ~current_protocol ~migration_level node client + in + if bake_until_new_cycle then + bake_until_next_cycle ~current_protocol node client + else unit diff --git a/tezt/manual_tests/migration_utils.mli b/tezt/manual_tests/migration_utils.mli new file mode 100644 index 000000000000..dcb7627ef410 --- /dev/null +++ b/tezt/manual_tests/migration_utils.mli @@ -0,0 +1,70 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Metastate AG *) +(* *) +(* 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 Tezt_tezos + +(** [bake_with_foundation client] try to bake with a randomly picked foundation + account. If the picked foundation account has no slot in the list then retry + with another account until a block have been baked. + + Default [foundation_index] is [1; 2; 3; 4; 5; 6; 7; 8]. + *) +val bake_with_foundation : ?foundation_index:int list -> Client.t -> unit Lwt.t + +(** Used to return a value of current protocol before migration that the + specific test might need. It can return unit if no prior value is needed. *) +type 'a get_prior_value = Node.t -> Client.t -> 'a Lwt.t + +(** A specific test for the new protocol after migration, that will be passed + the result returned from [get_prior_value]. *) +type 'a migration_test = Node.t -> Client.t -> 'a -> unit Lwt.t + +(** This template test checks the migrate of a protocol with a context imported + from a snapshot. See the tezos online documentation to have an in-depth + explanation of that test and how to use it. The documentation can be found at + this address: https://tezos.gitlab.io/developer/proposal_testing.html + + When [migrate_at_end_of_cycle] is set the test can be really long if the + used snapshot is not near the end of a period. Please in that case bake until + close to the end of a period prior to run this test, so you can reuse the + context easily. + + This function is to be used to easily create test for specific migration + (ex: see [Migration_007_008.register]). + + To define a new specific migration test please define two functions in the + [?specific_test] argument. The [get_prior_value] function will be run right + after starting the node. To run that function at a specific level, please + prepare the context to be at that level. *) +val template_test_migration : + ?yes_node_path:string -> + ?yes_wallet:string -> + ?migrate_at_end_of_cycle:bool -> + ?bake_until_new_cycle:bool -> + ?specific_test:'a get_prior_value * 'a migration_test -> + context:string -> + current_protocol:Protocol.t -> + string -> + unit Lwt.t -- GitLab From d7ff0734ada9e0d7894efb24dd4150de719907d7 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 3 Dec 2020 18:44:15 +0100 Subject: [PATCH 08/20] Tezt/manual_test:test mig 008 for new voting RPCs and sapling --- tezt/manual_tests/main.ml | 1 + tezt/manual_tests/migration_007_008.ml | 273 +++++++++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 tezt/manual_tests/migration_007_008.ml diff --git a/tezt/manual_tests/main.ml b/tezt/manual_tests/main.ml index c4b228770a27..f78b9181630b 100644 --- a/tezt/manual_tests/main.ml +++ b/tezt/manual_tests/main.ml @@ -29,5 +29,6 @@ let () = Migration_mainnet_alpha.register () ; + Migration_007_008.register () ; (* Test.run () should be the last statement, don't register afterwards! *) Test.run () diff --git a/tezt/manual_tests/migration_007_008.ml b/tezt/manual_tests/migration_007_008.ml new file mode 100644 index 000000000000..43a51963b510 --- /dev/null +++ b/tezt/manual_tests/migration_007_008.ml @@ -0,0 +1,273 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Metastate AG *) +(* *) +(* 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 Migration_utils + +let get_sapling_found ~account ~contract client = + let proc = Client.spawn_sapling_get_balance ~account ~contract client in + let* balance = + Lwt_stream.find + (fun line -> line =~ rex "Total Sapling funds .*") + (Lwt_io.read_lines (Process.stdout proc)) + in + return + Option.( + map + (fun balance -> balance =~* rex "Total Sapling funds ([\\d\\.]+)") + balance + |> join) + +let get_generated_sapling_address ~account client = + let proc = Client.spawn_sapling_generate_address ~account client in + let* address_opt = + Lwt_stream.find + (fun line -> line =~ rex "zet\\w+$") + (Lwt_io.read_lines (Process.stdout proc)) + in + return @@ Option.get address_opt + +let get_prior_value _node client = + let* level_before = RPC.Proto_007_delphi.get_current_level client in + return JSON.(level_before |-> "voting_period" |> as_int) + +let test node client voting_period_before = + let* current_level_json = RPC.Proto_007_delphi.get_current_level client in + let current_level = JSON.(current_level_json |-> "level" |> as_int) in + (* Test that the current_level RPC behaves as before even if the two following + fields are removed from the internal representation. *) + let* level_after = RPC.Proto_007_delphi.get_current_level client in + let level_level_position_after = + JSON.(level_after |-> "level_position" |> as_int) + in + let voting_period = JSON.(level_after |-> "voting_period" |> as_int) in + Log.info "test voting period info" ; + if voting_period <> voting_period_before + 1 then + Test.fail + "unexpected voting period %d expected %d in level" + voting_period + (voting_period_before + 1) ; + let voting_period_position = + JSON.(level_after |-> "voting_period_position" |> as_int) + in + if voting_period_position <> 0 then + Test.fail + "unexpected voting period position %d expected %d level" + voting_period_position + 0 ; + (* Test that votes/current_period returns the expected json *) + let* period = RPC.Proto_008_edo.Votes.get_current_period client in + let position = JSON.(period |-> "position" |> as_int) in + if voting_period_position <> 0 then + Test.fail + "unexpected voting period position %d expected %d in period" + position + 0 ; + let remaining = JSON.(period |-> "remaining" |> as_int) in + let* constants = RPC.Proto_008_edo.get_constants client in + let blocks_per_voting_period = + JSON.(constants |-> "blocks_per_voting_period" |> as_int) + in + if remaining <> blocks_per_voting_period - 1 then + Test.fail + "unexpected remaining %d expected %d in period" + remaining + (blocks_per_voting_period - 1) ; + let index = JSON.(period |-> "voting_period" |-> "index" |> as_int) in + if index <> voting_period_before + 1 then + Test.fail + "unexpected index %d expected %d in period" + index + (voting_period_before + 1) ; + let start_position = + JSON.(period |-> "voting_period" |-> "start_position" |> as_int) + in + if start_position <> level_level_position_after then + Test.fail + "unexpected start_position %d expected %d in period" + start_position + level_level_position_after ; + let kind = JSON.(period |-> "voting_period" |-> "kind" |> as_string) in + if kind <> "proposal" then + Test.fail "unexpected kind %s expected %s in period" kind "proposal" ; + (* Test that votes/current_kind behaves like before *) + let* kind = RPC.Proto_008_edo.Votes.get_current_period_kind client in + let kind = JSON.as_string kind in + if kind <> "proposal" then + Test.fail + "unexpected kind %s expected %s in current period kind" + kind + "proposal" ; + (* Test that successor period returns almost the same info as above. + It would be more interesting to run it at the end of a voting period. *) + let* period = RPC.Proto_008_edo.Votes.get_successor_period client in + let position = JSON.(period |-> "position" |> as_int) in + if position <> 1 then + Test.fail "unexpected position %d expected %d in succ period" position 1 ; + let remaining = JSON.(period |-> "remaining" |> as_int) in + let* constants = RPC.Proto_008_edo.get_constants client in + let blocks_per_voting_period = + JSON.(constants |-> "blocks_per_voting_period" |> as_int) + in + if remaining <> blocks_per_voting_period - 2 then + Test.fail + "unexpected remaining %d expected %d in succ period" + remaining + (blocks_per_voting_period - 2) ; + let index = JSON.(period |-> "voting_period" |-> "index" |> as_int) in + if index <> voting_period_before + 1 then + Test.fail + "unexpected index %d expected %d in succ period" + index + (voting_period_before + 1) ; + let start_position = + JSON.(period |-> "voting_period" |-> "start_position" |> as_int) + in + if start_position <> level_level_position_after then + Test.fail + "unexpected start_position %d expected %d in succ period" + start_position + level_level_position_after ; + let kind = JSON.(period |-> "voting_period" |-> "kind" |> as_string) in + if kind <> "proposal" then + Test.fail "unexpected kind %s expected %s in succ period" kind "proposal" ; + Log.info "test metadata" ; + (* metadata change appears only on first block of new protocol *) + let* () = bake_with_foundation client in + let* metadata = RPC.get_metadata client in + let metadata_level = JSON.(metadata |-> "level") in + assert (level_after <> metadata_level) ; + let metadata_kind = JSON.(metadata |-> "voting_period_kind" |> as_string) in + if metadata_kind <> kind then + Test.fail + "unexpected period kind %s expected %s in metadata" + metadata_kind + kind ; + let level_info = JSON.(metadata |-> "level_info") in + if JSON.(unannotate level_info = `Null) then + Test.fail "missing value level_info in metadata" ; + let voting_period_info = JSON.(metadata |-> "voting_period_info") in + if JSON.(unannotate voting_period_info = `Null) then + Test.fail "missing value voting_period_info in metadata" ; + (* originate a sapling contract and validate a transactions *) + let contract = "sapling" in + let alice = "alice" in + let bob = "bob" in + let* _hash = + Client.originate_contract + ~alias:contract + ~amount:(Tez.of_int 0) + ~src:"foundation1" + ~prg:"./src/proto_alpha/lib_protocol/test/contracts/sapling_contract.tz" + ~init:"{ }" + ~burn_cap:(Tez.of_int 3) + client + in + let* () = bake_with_foundation client in + let* _wait_block = Node.wait_for_level node (current_level + 1) in + let* () = + Client.sapling_generate_key + ~unencrypted:true + ~force:true + ~name:alice + client + in + let* () = + Client.sapling_use_key ~memo_size:8 ~account:alice ~contract client + in + let* () = + Client.sapling_generate_key ~unencrypted:true ~force:true ~name:bob client + in + let* () = + Client.sapling_use_key ~memo_size:8 ~account:bob ~contract client + in + let* alice_address = get_generated_sapling_address ~account:alice client in + let* () = + Client.sapling_shield + ~burn_cap:2 + ~amount:10 + ~source:"foundation1" + ~target:alice_address + ~contract + client + in + let* () = bake_with_foundation client in + let* _wait_block = Node.wait_for_level node (current_level + 2) in + let* alice_balance = get_sapling_found ~account:alice ~contract client in + assert (Option.get alice_balance |> int_of_string = 10) ; + let* bob_address = get_generated_sapling_address ~account:bob client in + let* () = + Client.sapling_forge_transaction + ~amount:10 + ~source:alice + ~target:bob_address + ~contract + client + in + let* () = + Client.sapling_submit_transaction + ~burn_cap:1 + ~account:"foundation2" + ~contract + client + in + let* () = bake_with_foundation client in + let* _wait_block = Node.wait_for_level node (current_level + 3) in + let* bob_balance = get_sapling_found ~account:bob ~contract client in + assert (Option.get bob_balance |> int_of_string = 10) ; + let* () = + Client.sapling_unshield + ~burn_cap:1 + ~amount:10 + ~source:bob + ~target:"foundation3" + ~contract + client + in + let* () = bake_with_foundation client in + let* _wait_block = Node.wait_for_level node (current_level + 4) in + unit + +let mainnet_context = "~/tezos-node-test" + +let test_migration_007_008 = + Test.register + ~__FILE__ + ~title:"stiching test" + ~tags: + [ "node"; + "user_activated"; + "protocol"; + Protocol.(tag Edo); + "migration"; + "stiching" ] + @@ fun () -> + template_test_migration + ~migrate_at_end_of_cycle:true + ~specific_test:(get_prior_value, test) + ~context:mainnet_context + ~current_protocol:Protocol.Delphi + Protocol.(hash Edo) + +let register () = test_migration_007_008 -- GitLab From cf53c57febbb42bdc5500c9992a72d6474861086 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 3 Dec 2020 17:44:45 +0100 Subject: [PATCH 09/20] script/prep_mig_script: adapt script to new test --- scripts/prepare_migration_test.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/prepare_migration_test.sh b/scripts/prepare_migration_test.sh index 3d1c6be1b71d..c135d059e220 100755 --- a/scripts/prepare_migration_test.sh +++ b/scripts/prepare_migration_test.sh @@ -223,19 +223,28 @@ then if ! [ -z "$proto_name" ] then full_hash=$(jq .hash < ${proto_dir}/lib_protocol/TEZOS_PROTOCOL) - sed -i.old -e 's/^let protocol = .*/let protocol = '$full_hash'/' ./tezt/manual_tests/migration.ml + short_hash=$(echo ${full_hash:1} | head -c 8 | tr '[:upper:]' '[:lower:]') fi import_snapshot "$snapshot_path" "$blockhash" + + find ./tezt/manual_tests/ -name "migration_*_*.ml" | + while IFS= read -r file; do + if [ -n "$proto_name" ]; then + sed -i.old -e 's/^let protocol_hash = .*/let protocol_hash = '"$full_hash"'/' "$file" + sed -i.old -e 's/^let protocol_tag = .*/let protocol_tag = "'"$short_hash"'"/' "$file" + fi + sed -i.old -e 's;^let mainnet_context = .*;let mainnet_context = "'"${context_dir}"'";' "$file" + done + [ -f "$context_dir/identity.json" ] && rm "$context_dir/identity.json" - sed -i.old -e 's;^let context = .*;let context = "'"$context_dir"'";' ./tezt/manual_tests/migration.ml # remove files generated by sed find . -name '*.old' -exec rm {} \; echo " Use the following commands to run the test: -$ dune exec ./tezt/manual_tests/main.exe -- --keep-temp migration +$ dune exec ./tezt/manual_tests/main.exe -- --keep-temp ${short_hash} After the test ends, note down the path of the temporary files $tmp_dir/tezt-XXXXXX, where XXXXXX are six random decimal figures. @@ -250,8 +259,9 @@ $ ./tezos-client -d $tmp_dir/tezt-XXXXXX/yes-wallet bake for foundation1 --minim In order to re-run the migration test, kill any node that may be running and use the command for running the test above (the script needs not to be run again). -Please adapt the test file ./tezt/manual_tests/migration.ml to your specific -needs." +Please create a test file +./tezt/manual_tests/migration_${pred_proto_version}_${proto_version}.ml to your +specific needs." elif [[ "$mode" == "manual" ]] then -- GitLab From 64092f54938e89f0778ffccbac1d39609f1570ce Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Thu, 3 Dec 2020 17:45:38 +0100 Subject: [PATCH 10/20] Ci: fix migration script test --- .gitlab/ci/integration.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab/ci/integration.yml b/.gitlab/ci/integration.yml index 7b71a7c3f737..4f8545752da7 100644 --- a/.gitlab/ci/integration.yml +++ b/.gitlab/ci/integration.yml @@ -22,12 +22,11 @@ script:prepare_migration_test: extends: .test_template before_script: - last_proto_name=$(find src -name "proto_[0-9][0-9][0-9]_*" | awk -F'/' '{print $NF}' | sort -r | head -1) - - last_proto_version=$(echo $last_proto_name | cut -d'_' -f2) + - last_proto_version=$(echo $last_proto_name | cut -d'_' -f2 | bc) - new_proto_version=$(printf "%03d" $((last_proto_version + 1))) - make script: - ./scripts/prepare_migration_test.sh manual "next_$new_proto_version" 1 - allow_failure: true # This test fails starting from 008 because bash thinks 008 is octal ############################################################ ## Stage: run OCaml integration tests ## -- GitLab From c93733181336701810b079e560e63c7a46519cc4 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Mon, 7 Dec 2020 14:03:49 +0100 Subject: [PATCH 11/20] CI: replace snapshot service --- .gitlab/ci/tezt.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitlab/ci/tezt.yml b/.gitlab/ci/tezt.yml index 0a6379bb2f2a..efcccf1b2983 100644 --- a/.gitlab/ci/tezt.yml +++ b/.gitlab/ci/tezt.yml @@ -17,12 +17,9 @@ tezt:manual:migration: when: manual before_script: - export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER=Y - - curl -s https://api.github.com/repos/Phlogi/tezos-snapshots/releases/latest | jq -r ".assets[] | select(.name) | .browser_download_url" | grep roll | xargs wget -q - - block_hash=$(echo mainnet.roll.* | sed -r 's/mainnet\.roll\.[0-9_-]+\.(.*)\.[0-9]+\.chain\.xz/\1/g') - - cat mainnet.roll.* | xz -d -v -T0 > mainnet.rolling - + - wget https://mainnet.xtz-shots.io/rolling -O mainnet.rolling - make - - scripts/prepare_migration_test.sh auto mainnet.rolling "$block_hash" + - scripts/prepare_migration_test.sh auto mainnet.rolling script: - dune exec ./tezt/manual_tests/main.exe -- migration --color --log-buffer-size 5000 --log-file tezt-migration.log artifacts: -- GitLab From 0d7a91aeef8a7b8c45f0321812fe9604d5c42a42 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Fri, 4 Dec 2020 09:48:22 +0100 Subject: [PATCH 12/20] script/snap_and_link: add hash to final protocol version --- scripts/snapshot_alpha_and_link.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/snapshot_alpha_and_link.sh b/scripts/snapshot_alpha_and_link.sh index 24239da5bebe..3a0b2de7dd2d 100755 --- a/scripts/snapshot_alpha_and_link.sh +++ b/scripts/snapshot_alpha_and_link.sh @@ -50,5 +50,10 @@ $script_dir/update_opam_test.sh echo "link_protocol.sh src/proto_${version_number}_${short_hash}" $script_dir/link_protocol.sh src/proto_${version_number}_${short_hash} +# activate in snapshoted protocol in +full_hash=$(jq .hash < $dir/lib_protocol/TEZOS_PROTOCOL | cut -d "\"" -f 2) +echo "add protocol to final protocol version" +echo "\n${full_hash}" >> src/lib_protocol_compiler/final_protocol_versions + echo "Done. You can now commit everything." echo "Don't forget to: git add src/proto_${version_number}_${short_hash}" -- GitLab From b351d39f71fbccfcbf1fb9a93dac6e196e2ef1ea Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Fri, 4 Dec 2020 09:49:12 +0100 Subject: [PATCH 13/20] script/prep_mig_test: allow to pass context in parameter --- scripts/prepare_migration_test.sh | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/scripts/prepare_migration_test.sh b/scripts/prepare_migration_test.sh index c135d059e220..64fc2c8d97a1 100755 --- a/scripts/prepare_migration_test.sh +++ b/scripts/prepare_migration_test.sh @@ -28,29 +28,35 @@ Calling: ./scripts/user_activated_upgrade.sh $f_proto_dir $f_mig_level." } import_snapshot () { - f_snapshot_path="$1" + f_path="$1" f_blockhash="$2" - ! [ -z "$f_blockhash" ] && f_blockhash_opt="--block $f_blockhash" - - # The command ${snapshot%.(rolling|full|archive} did not worked for no - # found reason - context_dir="${f_snapshot_path%.rolling}" - context_dir="${context_dir%.full}" - context_dir="${context_dir%.archive}" - context_dir="$tmp_dir/tezos-node-${context_dir##*/}" - if [ -d "$context_dir" ] + if [ -d "$f_path" ] then - echo " + echo " +Using context found in ${f_path}" + context_dir="$f_dir" + elif [ -f "$f_path" ] + then + context_dir="${f_path%.rolling}" + context_dir="${context_dir%.full}" + context_dir="${context_dir%.archive}" + context_dir="$tmp_dir/tezos-node-${context_dir##*/}" + if [ -d "$context_dir" ] + then + echo " Found existing context in directory ${context_dir} -If you want to re-import the context from ${f_snapshot_path} +If you want to re-import the context from ${f_path} please delete directory ${context_dir} The context in ${context_dir} will be used for the test." - else - echo " -Importing context from $f_snapshot_path into $context_dir." - ./tezos-node snapshot import "$f_snapshot_path" --data-dir "$context_dir" $f_blockhash_opt + else + echo " +Importing context from ${f_path} into ${context_dir}." + ! [ -z "$f_blockhash" ] && f_blockhash_opt="--block $f_blockhash" + ./tezos-node snapshot import "$f_path" --data-dir\ + "$context_dir" $f_blockhash_opt + fi fi } @@ -210,8 +216,9 @@ then fi # check if path exists - if ! [ -f "$snapshot_path" ] + if ! ( [ -z "$snapshot_path" ] || [ -e "$snapshot_path" ] ) then + echo "missing correct path for $snapshot_path" echo "$usage" exit 1 fi @@ -332,7 +339,6 @@ $ ./tezos-node snapshot import --data-dir $ ./tezos-node identity generate --data-dir " fi - echo " Use the following commands to start the node with the imported context: $ test_directory=\$(mktemp -d -t \"${context_dir##*/}-XXXX\") && cp -r \"$context_dir/.\" \"\$test_directory\" -- GitLab From 9b15baf1aec18dc344d113593d96e33ccc8ea88a Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Mon, 7 Dec 2020 13:48:42 +0100 Subject: [PATCH 14/20] script: shellcheck and shfmt protocol script --- scripts/link_protocol.sh | 89 +++++++++--------- scripts/prepare_migration_test.sh | 145 ++++++++++++++--------------- scripts/snapshot_alpha.sh | 98 ++++++++++--------- scripts/snapshot_alpha_and_link.sh | 30 +++--- scripts/user_activated_upgrade.sh | 34 ++++--- 5 files changed, 204 insertions(+), 192 deletions(-) diff --git a/scripts/link_protocol.sh b/scripts/link_protocol.sh index d42556b2dc35..a7637ecf6b8e 100755 --- a/scripts/link_protocol.sh +++ b/scripts/link_protocol.sh @@ -24,21 +24,21 @@ if [ ! -d "$1" ]; then exit 1 fi -new_version=$(basename $1 | awk -F'_' '{print $2}') -new_hash=$(basename $1 | awk -F'_' '{print $3}') -full_hash=$(jq .hash < $1/lib_protocol/TEZOS_PROTOCOL) +new_version=$(basename "$1" | awk -F'_' '{print $2}') +new_hash=$(basename "$1" | awk -F'_' '{print $3}') +full_hash=$(jq .hash <"$1"/lib_protocol/TEZOS_PROTOCOL) replacement=${new_version}-${new_hash} -if [[ -z "${new_version}" || -z "${new_hash}" || -z "${full_hash}" ]] ; then +if [[ -z "${new_version}" || -z "${new_hash}" || -z "${full_hash}" ]]; then echo "$usage" exit 1 fi # The pattern to look for is "00X-". # Once found it's either replaced or the line is duplicated and then replaced -old_version=$( printf '%03d' $((10#$new_version -1)) ) -old_dir=$(ls -d src/proto_${old_version}_*) -old_hash=$(basename $old_dir | awk -F'_' '{print $3}') -pattern=${old_version}-${old_hash} +old_version=$(printf '%03d' $((10#$new_version - 1))) +old_dir=$(ls -d src/proto_"${old_version}"_*) +old_hash=$(basename "$old_dir" | awk -F'_' '{print $3}') +pattern="${old_version}"-"${old_hash}" echo "Pattern to duplicate / substitute: $pattern" @@ -48,15 +48,14 @@ duplicate_and_replace() { REPLACEMENT=$2 shift 2 - for file in $* - do + for file in "$@"; do echo "Adding $replacement in: $file" awk '{ print if ($0 ~ PATTERN) { sub(PATTERN,REPLACEMENT) print - }}' PATTERN=$PATTERN REPLACEMENT=$REPLACEMENT "$file" > tmp_file + }}' PATTERN="$PATTERN" REPLACEMENT="$REPLACEMENT" "$file" >tmp_file mv tmp_file "$file" done } @@ -66,13 +65,10 @@ duplicate_and_replace_only_1_occ() { REPLACEMENT=$2 shift 2 - for file in $* - do + for file in "$@"; do echo "Adding $replacement in: $file (only one occurrence)" awk '{ - if ( prevlast !~ PATTERN\ - && last ~ PATTERN\ - && $0 !~ PATTERN) { + if (prevlast !~ PATTERN && last ~ PATTERN && $0 !~ PATTERN) { gsub(PATTERN,REPLACEMENT,last) print last } @@ -80,8 +76,8 @@ duplicate_and_replace_only_1_occ() { {prevlast = last} {last = $0} - }' PATTERN=$PATTERN REPLACEMENT=$REPLACEMENT "$file" > tmp_file - mv tmp_file "$file" + }' PATTERN="$PATTERN" REPLACEMENT="$REPLACEMENT" "$file" >tmp_file + mv tmp_file "$file" done } @@ -90,14 +86,13 @@ duplicate_and_replace_when_3_occ() { REPLACEMENT=$2 shift 2 - for file in $* - do + for file in "$@"; do echo "Adding $replacement in: $file (when 3 occurrences)" + #allow '\' to split line in literal + #shellcheck disable=SC1004 awk '{ - if ( prevprevlast ~ PATTERN\ - && prevlast ~ PATTERN\ - && last ~ PATTERN\ - && $0 !~ PATTERN) { + if (prevprevlast ~ PATTERN && prevlast ~ PATTERN\ + && last ~ PATTERN && $0 !~ PATTERN) { gsub(PATTERN, REPLACEMENT, prevprevlast) gsub(PATTERN, REPLACEMENT, prevlast) gsub(PATTERN, REPLACEMENT, last) @@ -110,36 +105,36 @@ duplicate_and_replace_when_3_occ() { {prevlast = last} {last = $0} - }' PATTERN=$PATTERN REPLACEMENT=$REPLACEMENT "$file" > tmp_file - mv tmp_file "$file" + }' PATTERN="$PATTERN" REPLACEMENT="$REPLACEMENT" "$file" >tmp_file + mv tmp_file "$file" done } # the minimum needed, although you can't bake -duplicate_and_replace ${pattern} ${replacement} active_protocol_versions +duplicate_and_replace "${pattern}" "${replacement}" active_protocol_versions # activate in client to bake and use RPCs -duplicate_and_replace_when_3_occ -${pattern} -${replacement} \ - src/bin_client/dune -duplicate_and_replace_only_1_occ -${pattern} -${replacement} \ - src/bin_client/dune -duplicate_and_replace -${pattern} -${replacement} \ - src/bin_client/tezos-client.opam +duplicate_and_replace_when_3_occ -"${pattern}" -"${replacement}" \ + src/bin_client/dune +duplicate_and_replace_only_1_occ -"${pattern}" -"${replacement}" \ + src/bin_client/dune +duplicate_and_replace -"${pattern}" -"${replacement}" \ + src/bin_client/tezos-client.opam # activate in node -duplicate_and_replace_when_3_occ -${pattern} -${replacement} \ - src/bin_node/dune -duplicate_and_replace_only_1_occ -${pattern} -${replacement} \ - src/bin_node/dune -duplicate_and_replace -${pattern} -${replacement} \ - src/bin_node/tezos-node.opam -duplicate_and_replace -${pattern} -${replacement} \ - src/bin_validation/{dune,tezos-validator.opam} +duplicate_and_replace_when_3_occ -"${pattern}" -"${replacement}" \ + src/bin_node/dune +duplicate_and_replace_only_1_occ -"${pattern}" -"${replacement}" \ + src/bin_node/dune +duplicate_and_replace -"${pattern}" -"${replacement}" \ + src/bin_node/tezos-node.opam +duplicate_and_replace -"${pattern}" -"${replacement}" \ + src/bin_validation/{dune,tezos-validator.opam} # activate in codec -duplicate_and_replace_when_3_occ -${pattern} -${replacement} \ - src/bin_codec/dune -duplicate_and_replace_only_1_occ -${pattern} -${replacement} \ - src/bin_codec/dune -duplicate_and_replace -${pattern} -${replacement} \ - src/bin_codec/tezos-codec.opam +duplicate_and_replace_when_3_occ -"${pattern}" -"${replacement}" \ + src/bin_codec/dune +duplicate_and_replace_only_1_occ -"${pattern}" -"${replacement}" \ + src/bin_codec/dune +duplicate_and_replace -"${pattern}" -"${replacement}" \ + src/bin_codec/tezos-codec.opam diff --git a/scripts/prepare_migration_test.sh b/scripts/prepare_migration_test.sh index 64fc2c8d97a1..5cca60b3eae5 100755 --- a/scripts/prepare_migration_test.sh +++ b/scripts/prepare_migration_test.sh @@ -2,23 +2,24 @@ set -e -snapshot_protocol () { +snapshot_protocol() { f_proto_name="$1" f_proto_version="$2" f_proto_dir="$3" # snapshot protocol alpha into new directory echo " -Calling: ./scripts/snapshot_alpha $f_proto_name." - ./scripts/snapshot_alpha.sh "$f_proto_name" +Calling: ./scripts/snapshot_alpha ${f_proto_name}_${f_proto_version}" + ./scripts/snapshot_alpha.sh "${f_proto_name}_${f_proto_version}" + proto_dir=$(ls -d src/proto_"${proto_version}"_*/) # link new protocol for the shell and client echo " -Calling: ./scripts/link_protocol.sh $f_proto_dir." - ./scripts/link_protocol.sh $f_proto_dir +Calling: ./scripts/link_protocol.sh $proto_dir." + ./scripts/link_protocol.sh "$proto_dir" } -user_activated_upgrade () { +user_activated_upgrade() { f_proto_dir="$1" f_mig_level="$2" # activate the migration at a specific level @@ -27,23 +28,19 @@ Calling: ./scripts/user_activated_upgrade.sh $f_proto_dir $f_mig_level." ./scripts/user_activated_upgrade.sh "$f_proto_dir" "$f_mig_level" } -import_snapshot () { +import_snapshot() { f_path="$1" f_blockhash="$2" - - if [ -d "$f_path" ] - then - echo " + if [ -d "$f_path" ]; then + echo " Using context found in ${f_path}" - context_dir="$f_dir" - elif [ -f "$f_path" ] - then + context_dir="$f_path" + elif [ -f "$f_path" ]; then context_dir="${f_path%.rolling}" context_dir="${context_dir%.full}" context_dir="${context_dir%.archive}" context_dir="$tmp_dir/tezos-node-${context_dir##*/}" - if [ -d "$context_dir" ] - then + if [ -d "$context_dir" ]; then echo " Found existing context in directory ${context_dir} If you want to re-import the context from ${f_path} @@ -52,29 +49,34 @@ please delete directory ${context_dir} The context in ${context_dir} will be used for the test." else echo " -Importing context from ${f_path} into ${context_dir}." - ! [ -z "$f_blockhash" ] && f_blockhash_opt="--block $f_blockhash" - ./tezos-node snapshot import "$f_path" --data-dir\ - "$context_dir" $f_blockhash_opt +Importing context from ${f_path} into ${context_dir}. +" + if [ -n "$f_blockhash" ]; then + ./tezos-node snapshot import "$f_path" \ + --data-dir "$context_dir" \ + --block "$f_blockhash" + else + ./tezos-node snapshot import "$f_path" \ + --data-dir "$context_dir" + fi fi fi } -generate_identities (){ +generate_identities() { f_context_dir="$1" ./tezos-node identity generate --data-dir "$f_context_dir" } -patch_yes_node () { +patch_yes_node() { echo " Patching the code to obtain a yes-node." - patch -p1 < ./scripts/yes-node.patch + patch -p1 <./scripts/yes-node.patch } -create_yes_wallet () { +create_yes_wallet() { yes_wallet="$tmp_dir/yes-wallet" - if [ -d "$yes_wallet" ] - then + if [ -d "$yes_wallet" ]; then echo " Found existing yes-wallet in directory ${yes_wallet}. The yes-wallet in ${yes_wallet} will be used for the test @@ -89,12 +91,12 @@ Creating a yes-wallet in directory ${yes_wallet}." echo "You can now bake for foundation{1..8}." } +# SCRIPT START + #setting tmp dir -if ! [[ -z "$TMP" ]] -then +if [ -n "$TMP" ]; then tmp_dir="$TMP" -elif ! [[ -z "$TMPDIR" ]] -then +elif [ -n "$TMPDIR" ]; then tmp_dir="$TMPDIR" else tmp_dir="/tmp" @@ -167,47 +169,51 @@ in the imported chain is . " # manual or auto mode -# -if ! ( [[ $1 == "manual" ]] || [[ $1 == "auto" ]] ) || [ $# -lt 2 ] -then +if ! { [ "$1" == "manual" ] || [ "$1" == "auto" ]; } || [ $# -lt 2 ]; then echo "$usage" - echo "$manual" exit 1 else mode="$1" fi #set variable related to protocol, in particular \$proto_version and \$pred_proto_version -if [[ "$2" =~ ^[a-z]+_[0-9][0-9][0-9]$ ]] -then - proto_name="$2" - proto_version=$(echo "$proto_name" | cut -d'_' -f2) +if [[ "$2" =~ ^[a-z]+_[0-9][0-9][0-9]$ ]]; then + proto_name_version="$2" + + proto_name=$(echo "$proto_name_version" | cut -d'_' -f1) + proto_version=$(echo "$proto_name_version" | cut -d'_' -f2 | bc) + + pred_proto_version=$(printf "%03d" $((proto_version - 1))) + + # This line could be merged to previous assignment but it's need because + # bash consider "008" to be octal + proto_version=$(printf "%03d" "$proto_version") proto_dir="src/proto_${proto_version}_*/" - pred_proto_version=$(printf "%03d" $((10#$proto_version -1))) else - pred_proto_name=$(find src -name "proto_[0-9][0-9][0-9]_*" | awk -F'/' '{print $NF}' | sort -r | head -1) - pred_proto_version=$(echo $pred_proto_name | cut -d'_' -f2) + pred_proto_name_version=$(find src -name "proto_[0-9][0-9][0-9]_*" | awk -F'/' '{print $NF}' | sort -r | head -1) + pred_proto_version=$(echo "$pred_proto_name_version" | cut -d'_' -f2 | bc) - proto_version=($pred_proto_version +1) + proto_version=$(printf "%03d" $((pred_proto_version + 1))) + + # This line could be merged to previous assignment but it's need because + # bash consider "008" to be octal + pred_proto_version=$(printf "%03d" "$pred_proto_version") proto_dir="src/proto_alpha/" fi # now calls correct scripts and renaming -if ! [ -z "$proto_name" ] -then +if [ -n "$proto_name" ]; then snapshot_protocol "$proto_name" "$proto_version" "$proto_dir" fi echo " Setting environment for $mode test" -if [[ $mode == "auto" ]] -then +if [[ $mode == "auto" ]]; then #set \$path - if ! [ -z "$proto_name" ] - then + if [ -n "$proto_name" ]; then snapshot_path="$3" blockhash="$4" else @@ -216,8 +222,7 @@ then fi # check if path exists - if ! ( [ -z "$snapshot_path" ] || [ -e "$snapshot_path" ] ) - then + if ! { [ -z "$snapshot_path" ] || [ -e "$snapshot_path" ]; }; then echo "missing correct path for $snapshot_path" echo "$usage" exit 1 @@ -227,10 +232,9 @@ then make - if ! [ -z "$proto_name" ] - then - full_hash=$(jq .hash < ${proto_dir}/lib_protocol/TEZOS_PROTOCOL) - short_hash=$(echo ${full_hash:1} | head -c 8 | tr '[:upper:]' '[:lower:]') + if [ -n "$proto_name" ]; then + full_hash=$(jq .hash <${proto_dir}/lib_protocol/TEZOS_PROTOCOL) + short_hash=$(echo "${full_hash:1}" | head -c 8 | tr '[:upper:]' '[:lower:]') fi import_snapshot "$snapshot_path" "$blockhash" @@ -238,8 +242,8 @@ then find ./tezt/manual_tests/ -name "migration_*_*.ml" | while IFS= read -r file; do if [ -n "$proto_name" ]; then - sed -i.old -e 's/^let protocol_hash = .*/let protocol_hash = '"$full_hash"'/' "$file" - sed -i.old -e 's/^let protocol_tag = .*/let protocol_tag = "'"$short_hash"'"/' "$file" + sed -i.old -e 's/^let protocol_hash = .*/let protocol_hash = '"$full_hash"'/' "$file" + sed -i.old -e 's/^let protocol_tag = .*/let protocol_tag = "'"$short_hash"'"/' "$file" fi sed -i.old -e 's;^let mainnet_context = .*;let mainnet_context = "'"${context_dir}"'";' "$file" done @@ -270,11 +274,9 @@ Please create a test file ./tezt/manual_tests/migration_${pred_proto_version}_${proto_version}.ml to your specific needs." -elif [[ "$mode" == "manual" ]] -then +elif [[ "$mode" == "manual" ]]; then #set \$level \$path - if ! [ -z $proto_name ] - then + if [ -n "$proto_name" ]; then mig_level=$3 snapshot_path=$4 blockhash=$5 @@ -285,20 +287,18 @@ then fi # check if \$level is set - if [ -z $mig_level ] - then - echo $usage + if [ -z "$mig_level" ]; then + echo "$usage" exit 1 fi - user_activated_upgrade $proto_dir $mig_level + user_activated_upgrade $proto_dir "$mig_level" - pred_full_hash=$(jq -r .hash < src/proto_${pred_proto_version}_*/lib_protocol/TEZOS_PROTOCOL) - pred_short_hash=$(echo $pred_full_hash | head -c 8) + pred_full_hash=$(jq -r .hash > src/lib_protocol_compiler/final_protocol_versions +echo "${full_hash}" >>src/lib_protocol_compiler/final_protocol_versions echo "Done. You can now commit everything." echo "Don't forget to: git add src/proto_${version_number}_${short_hash}" diff --git a/scripts/user_activated_upgrade.sh b/scripts/user_activated_upgrade.sh index 6c72b1ec3f20..5a12788b02c7 100755 --- a/scripts/user_activated_upgrade.sh +++ b/scripts/user_activated_upgrade.sh @@ -34,29 +34,33 @@ fi if [[ $1 =~ ^.*/proto_[0-9]{3}_.*$ ]] then - version=$(echo "$1" | sed 's/.*proto_\([0-9]\{3\}\)_.*/\1/') - pred=$(printf "%03d" $((10#$version -1))) - pred_full_hash=$(jq -r .hash < src/proto_${pred}_*/lib_protocol/TEZOS_PROTOCOL) - pred_short_hash=$(echo $pred_full_hash | head -c 8) + version=$(echo "$1" | sed 's/.*proto_\([0-9]\{3\}\)_.*/\1/' | bc) + pred_version=$(printf "%03d" $((version - 1))) + pred_full_hash=$(jq -r .hash < src/proto_"${pred_version}"_*/lib_protocol/TEZOS_PROTOCOL) + pred_short_hash=$(echo "$pred_full_hash" | head -c 8) - full_hash=$(jq -r .hash < $1/lib_protocol/TEZOS_PROTOCOL) + full_hash=$(jq -r .hash < "$1"/lib_protocol/TEZOS_PROTOCOL) else pred_version_dir=$(find src -name "proto_00*" -printf '%P\n' | sort -r | head -1) - pred=$(echo $pred_version_dir | cut -d'_' -f2) - pred_full_hash=$(jq -r .hash < src/proto_${pred}_*/lib_protocol/TEZOS_PROTOCOL) - pred_short_hash=$(echo $pred_full_hash | head -c 8) + pred_version=$(echo "$pred_version_dir" | cut -d'_' -f2 | bc) - version=$((pred +1)) + version=$(printf "%03d" $((pred_version + 1))) + + # This line could be merged to previous assignment but it's need because + # bash consider "008" to be octal + pred_version=$(printf "%03d" "$pred_version") + pred_full_hash=$(jq -r .hash < src/proto_"${pred_version}"_*/lib_protocol/TEZOS_PROTOCOL) + pred_short_hash=$(echo "$pred_full_hash" | head -c 8) full_hash=$(jq -r .hash < src/proto_alpha/lib_protocol/TEZOS_PROTOCOL) fi level=$2 -if (( $level > 28082 )); then +if (( level > 28082 )); then # we are on a real network and we need a yes-node and yes-wallet to bake # replace existing upgrades - awk -v level=$level -v full_hash=$full_hash ' + awk -v level="$level" -v full_hash="$full_hash" ' BEGIN{found=0}{ if (!found && $0 ~ "~user_activated_upgrades") {found=1; printf " ~user_activated_upgrades:\n [ (%dl, \"%s\") ]\n", level, full_hash} @@ -72,16 +76,16 @@ else { else # we are in sandbox # add upgrade to the sandbox - awk -v level=$level -v full_hash=$full_hash ' + awk -v level="$level" -v full_hash="$full_hash" ' { print if ($0 ~ "~alias:\"sandbox\"") { printf " ~user_activated_upgrades:\n [ (%dl, \"%s\") ]\n", level, full_hash } }' src/bin_node/node_config_file.ml > tmp_file mv tmp_file src/bin_node/node_config_file.ml - sed -i.old "s/\$bin_dir\/..\/proto_alpha\/parameters\/sandbox-parameters.json/\$bin_dir\/..\/proto_${pred}_${pred_short_hash}\/parameters\/sandbox-parameters.json/" src/bin_client/tezos-init-sandboxed-client.sh - sed -i.old "s/activate_alpha()/activate_${pred}_${pred_short_hash}()/" src/bin_client/tezos-init-sandboxed-client.sh - sed -i.old "s/tezos-activate-alpha/tezos-activate-${pred}-${pred_short_hash}/" src/bin_client/tezos-init-sandboxed-client.sh + sed -i.old "s/\$bin_dir\/..\/proto_alpha\/parameters\/sandbox-parameters.json/\$bin_dir\/..\/proto_${pred_version}_${pred_short_hash}\/parameters\/sandbox-parameters.json/" src/bin_client/tezos-init-sandboxed-client.sh + sed -i.old "s/activate_alpha()/activate_${pred_version}_${pred_short_hash}()/" src/bin_client/tezos-init-sandboxed-client.sh + sed -i.old "s/tezos-activate-alpha/tezos-activate-${pred_version}-${pred_short_hash}/" src/bin_client/tezos-init-sandboxed-client.sh sed -i.old "s/activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK/activate protocol $pred_full_hash/" src/bin_client/tezos-init-sandboxed-client.sh rm src/bin_client/tezos-init-sandboxed-client.sh.old echo "The sandbox will now switch to $full_hash at level $level." -- GitLab From 93c9875a5f5bf83f017f01846edee9d0f310197e Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Mon, 14 Dec 2020 11:42:53 +0100 Subject: [PATCH 15/20] CI: remove repetitive make call --- .gitlab/ci/integration.yml | 1 - .gitlab/ci/tezt.yml | 3 --- 2 files changed, 4 deletions(-) diff --git a/.gitlab/ci/integration.yml b/.gitlab/ci/integration.yml index 4f8545752da7..b6bf7215a6fd 100644 --- a/.gitlab/ci/integration.yml +++ b/.gitlab/ci/integration.yml @@ -24,7 +24,6 @@ script:prepare_migration_test: - last_proto_name=$(find src -name "proto_[0-9][0-9][0-9]_*" | awk -F'/' '{print $NF}' | sort -r | head -1) - last_proto_version=$(echo $last_proto_name | cut -d'_' -f2 | bc) - new_proto_version=$(printf "%03d" $((last_proto_version + 1))) - - make script: - ./scripts/prepare_migration_test.sh manual "next_$new_proto_version" 1 diff --git a/.gitlab/ci/tezt.yml b/.gitlab/ci/tezt.yml index efcccf1b2983..bd64717f0ad4 100644 --- a/.gitlab/ci/tezt.yml +++ b/.gitlab/ci/tezt.yml @@ -2,8 +2,6 @@ # we still get the artifact (CI timeouts cause artifacts to not be uploaded). tezt:main: extends: .test_template - before_script: - - make script: - dune exec tezt/tests/main.exe -- --color --log-buffer-size 5000 --log-file tezt.log --global-timeout 3300 --time artifacts: @@ -18,7 +16,6 @@ tezt:manual:migration: before_script: - export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER=Y - wget https://mainnet.xtz-shots.io/rolling -O mainnet.rolling - - make - scripts/prepare_migration_test.sh auto mainnet.rolling script: - dune exec ./tezt/manual_tests/main.exe -- migration --color --log-buffer-size 5000 --log-file tezt-migration.log -- GitLab From d780c43e4add525bb1ef8622dc30d915694ceab4 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Fri, 22 Jan 2021 13:14:55 +0100 Subject: [PATCH 16/20] tezt/test: keep only short test because of bug There is a bug that don't allow to run multiple test in on run with --keep-temp. Because of that it does not make a lot of sens to register this test twice. This commit could be reverted when that bug is fixed --- tezt/manual_tests/migration_mainnet_alpha.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/manual_tests/migration_mainnet_alpha.ml b/tezt/manual_tests/migration_mainnet_alpha.ml index 4fcbd2179f25..870122e33d60 100644 --- a/tezt/manual_tests/migration_mainnet_alpha.ml +++ b/tezt/manual_tests/migration_mainnet_alpha.ml @@ -53,4 +53,4 @@ let test_migration ~long = ~current_protocol protocol_hash -let register () = test_migration ~long:true ; test_migration ~long:false +let register () = test_migration ~long:false -- GitLab From 1a071465bab5b8eec279b5115d868d3a9fd48bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 25 Jan 2021 10:27:02 +0100 Subject: [PATCH 17/20] Scripts: snapshot alpha - replace protocol-functor --- scripts/snapshot_alpha.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/snapshot_alpha.sh b/scripts/snapshot_alpha.sh index 3c3ac90b0b58..46745a60839e 100755 --- a/scripts/snapshot_alpha.sh +++ b/scripts/snapshot_alpha.sh @@ -117,6 +117,7 @@ sed -i.old -e 's/"hash": "[^"]*",/"hash": "'"${long_hash}"'",/' \ #shellcheck disable=SC2046 sed -i.old -e s/protocol_alpha/protocol_"${version}"_"${short_hash}"/ \ -e s/protocol-alpha/protocol-"${version}"-"${short_hash}"/ \ + -e s/protocol-functor-alpha/protocol-functor-"${version}"-"${short_hash}"/ \ $(find . -type f) # word splitting in needed to list all file -- GitLab From e0c29cfdc2ff6d99a55ec4fdb3e831ca4a925c8f Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 16 Feb 2021 14:34:54 +0100 Subject: [PATCH 18/20] proto/client: open module in dune --- src/proto_alpha/lib_client/dune | 1 + src/proto_alpha/lib_client/mockup.ml | 2 +- src/proto_alpha/lib_client/proxy.ml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_client/dune b/src/proto_alpha/lib_client/dune index a4887b4a3f18..9e08c5bd32c7 100644 --- a/src/proto_alpha/lib_client/dune +++ b/src/proto_alpha/lib_client/dune @@ -17,6 +17,7 @@ -open Tezos_client_base -open Tezos_protocol_alpha -open Tezos_protocol_alpha_parameters + -open Tezos_protocol_plugin_alpha -open Tezos_rpc))) (rule diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index c98807e07d6e..709bb78811a4 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -504,7 +504,7 @@ let () = module Protocol = Protocol_client_context.Lifted_protocol module Block_services = Protocol_client_context.Alpha_block_services - let directory = Tezos_protocol_plugin_alpha.Plugin.RPC.rpc_services + let directory = Plugin.RPC.rpc_services let init = mem_init diff --git a/src/proto_alpha/lib_client/proxy.ml b/src/proto_alpha/lib_client/proxy.ml index 0d2ddf8f32bc..20dcedf6e687 100644 --- a/src/proto_alpha/lib_client/proxy.ml +++ b/src/proto_alpha/lib_client/proxy.ml @@ -131,7 +131,7 @@ let () = let protocol_hash = Protocol.hash - let directory = Tezos_protocol_plugin_alpha.Plugin.RPC.rpc_services + let directory = Plugin.RPC.rpc_services let hash = Protocol_client_context.Alpha_block_services.hash -- GitLab From 1e64b2c73ce96272fa3020a1b4b50418299b7a68 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 16 Feb 2021 14:35:11 +0100 Subject: [PATCH 19/20] proto/plugin: open module in dune --- src/proto_alpha/lib_plugin/dune | 3 ++- src/proto_alpha/lib_plugin/registerer.ml | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_plugin/dune b/src/proto_alpha/lib_plugin/dune index a45df7a6bbf8..33d1a889f1de 100644 --- a/src/proto_alpha/lib_plugin/dune +++ b/src/proto_alpha/lib_plugin/dune @@ -18,7 +18,8 @@ (modules Registerer) (flags (:standard -open Tezos_base__TzPervasives -open Tezos_protocol_plugin_alpha - -open Tezos_shell))) + -open Tezos_shell + -open Tezos_protocol_plugin_alpha))) (rule (alias runtest_lint) diff --git a/src/proto_alpha/lib_plugin/registerer.ml b/src/proto_alpha/lib_plugin/registerer.ml index 2c9c465a125a..8824909c91c6 100644 --- a/src/proto_alpha/lib_plugin/registerer.ml +++ b/src/proto_alpha/lib_plugin/registerer.ml @@ -23,5 +23,4 @@ (* *) (*****************************************************************************) -let () = - Prevalidator_filters.register (module Tezos_protocol_plugin_alpha.Plugin) +let () = Prevalidator_filters.register (module Plugin) -- GitLab From 9023f30d0e794d31877efb3cc97ce6a8a4eddf15 Mon Sep 17 00:00:00 2001 From: Sylvain Ribstein Date: Tue, 16 Feb 2021 14:40:02 +0100 Subject: [PATCH 20/20] script: add check for 008 to disambiguate which protocol --- scripts/prepare_migration_test.sh | 9 ++++++++- scripts/user_activated_upgrade.sh | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/prepare_migration_test.sh b/scripts/prepare_migration_test.sh index 5cca60b3eae5..0ced3c36afa6 100755 --- a/scripts/prepare_migration_test.sh +++ b/scripts/prepare_migration_test.sh @@ -294,7 +294,14 @@ elif [[ "$mode" == "manual" ]]; then user_activated_upgrade $proto_dir "$mig_level" - pred_full_hash=$(jq -r .hash