diff --git a/tests_python/tests_014/test_client_without_node.py b/tests_python/tests_014/test_client_without_node.py index f07d0da3cc673f9db8f10f5de1f2c5eafcef7ac4..e8d0550fa8409dfb7c2e7b232c5547a4be919c84 100644 --- a/tests_python/tests_014/test_client_without_node.py +++ b/tests_python/tests_014/test_client_without_node.py @@ -141,19 +141,6 @@ class TestStopLoopPassword: client.transfer(0.1, 'encrypted_account', 'bootstrap1', stdin=stdin) -@pytest.mark.client -class TestChainId: - def test_chain_id_block_hash(self, nodeless_client: Client): - block_hash = 'BKyFui5WPY1n3e9aKF3qd2kGBKBtHu3rtm5miYFnUagJC1BdHTF' - prms = ['compute', 'chain', 'id', 'from', 'block', 'hash', block_hash] - assert nodeless_client.run(prms).strip() == 'NetXuwrXPL4VeX5' - - def test_chain_id_seed(self, nodeless_client: Client): - seed = 'choucroute' - prms = ['compute', 'chain', 'id', 'from', 'seed', seed] - assert nodeless_client.run(prms).strip() == 'NetXLGmPi3c5DXf' - - def _write_config_file( client: Client, filename: str, config_dict: Optional[dict] ): diff --git a/tests_python/tests_015/test_client_without_node.py b/tests_python/tests_015/test_client_without_node.py index f07d0da3cc673f9db8f10f5de1f2c5eafcef7ac4..e8d0550fa8409dfb7c2e7b232c5547a4be919c84 100644 --- a/tests_python/tests_015/test_client_without_node.py +++ b/tests_python/tests_015/test_client_without_node.py @@ -141,19 +141,6 @@ class TestStopLoopPassword: client.transfer(0.1, 'encrypted_account', 'bootstrap1', stdin=stdin) -@pytest.mark.client -class TestChainId: - def test_chain_id_block_hash(self, nodeless_client: Client): - block_hash = 'BKyFui5WPY1n3e9aKF3qd2kGBKBtHu3rtm5miYFnUagJC1BdHTF' - prms = ['compute', 'chain', 'id', 'from', 'block', 'hash', block_hash] - assert nodeless_client.run(prms).strip() == 'NetXuwrXPL4VeX5' - - def test_chain_id_seed(self, nodeless_client: Client): - seed = 'choucroute' - prms = ['compute', 'chain', 'id', 'from', 'seed', seed] - assert nodeless_client.run(prms).strip() == 'NetXLGmPi3c5DXf' - - def _write_config_file( client: Client, filename: str, config_dict: Optional[dict] ): diff --git a/tests_python/tests_016/test_client_without_node.py b/tests_python/tests_016/test_client_without_node.py index f07d0da3cc673f9db8f10f5de1f2c5eafcef7ac4..e8d0550fa8409dfb7c2e7b232c5547a4be919c84 100644 --- a/tests_python/tests_016/test_client_without_node.py +++ b/tests_python/tests_016/test_client_without_node.py @@ -141,19 +141,6 @@ class TestStopLoopPassword: client.transfer(0.1, 'encrypted_account', 'bootstrap1', stdin=stdin) -@pytest.mark.client -class TestChainId: - def test_chain_id_block_hash(self, nodeless_client: Client): - block_hash = 'BKyFui5WPY1n3e9aKF3qd2kGBKBtHu3rtm5miYFnUagJC1BdHTF' - prms = ['compute', 'chain', 'id', 'from', 'block', 'hash', block_hash] - assert nodeless_client.run(prms).strip() == 'NetXuwrXPL4VeX5' - - def test_chain_id_seed(self, nodeless_client: Client): - seed = 'choucroute' - prms = ['compute', 'chain', 'id', 'from', 'seed', seed] - assert nodeless_client.run(prms).strip() == 'NetXLGmPi3c5DXf' - - def _write_config_file( client: Client, filename: str, config_dict: Optional[dict] ): diff --git a/tests_python/tests_alpha/test_client_without_node.py b/tests_python/tests_alpha/test_client_without_node.py index f07d0da3cc673f9db8f10f5de1f2c5eafcef7ac4..e8d0550fa8409dfb7c2e7b232c5547a4be919c84 100644 --- a/tests_python/tests_alpha/test_client_without_node.py +++ b/tests_python/tests_alpha/test_client_without_node.py @@ -141,19 +141,6 @@ class TestStopLoopPassword: client.transfer(0.1, 'encrypted_account', 'bootstrap1', stdin=stdin) -@pytest.mark.client -class TestChainId: - def test_chain_id_block_hash(self, nodeless_client: Client): - block_hash = 'BKyFui5WPY1n3e9aKF3qd2kGBKBtHu3rtm5miYFnUagJC1BdHTF' - prms = ['compute', 'chain', 'id', 'from', 'block', 'hash', block_hash] - assert nodeless_client.run(prms).strip() == 'NetXuwrXPL4VeX5' - - def test_chain_id_seed(self, nodeless_client: Client): - seed = 'choucroute' - prms = ['compute', 'chain', 'id', 'from', 'seed', seed] - assert nodeless_client.run(prms).strip() == 'NetXLGmPi3c5DXf' - - def _write_config_file( client: Client, filename: str, config_dict: Optional[dict] ): diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 10e8c90d14439c98ca5866d4617729c58bebd362..79b49876dd6901b2737ed07bf00798553b4ac6bf 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -3216,3 +3216,27 @@ let sapling_submit ?wait ?burn_cap ~file ~alias_tz ~sapling_contract ?json ?json client |> Process.check + +let spawn_compute_chain_id_from_block_hash ?endpoint client block_hash = + spawn_command ?endpoint client + @@ ["compute"; "chain"; "id"; "from"; "block"; "hash"; block_hash] + +(** Run [tezos-client compute chain id from block hash]. *) +let compute_chain_id_from_block_hash ?endpoint client block_hash = + let* output = + spawn_compute_chain_id_from_block_hash ?endpoint client block_hash + |> Process.check_and_read_stdout + in + return (String.trim output) + +let spawn_compute_chain_id_from_seed ?endpoint client seed = + spawn_command ?endpoint client + @@ ["compute"; "chain"; "id"; "from"; "seed"; seed] + +(** Run [tezos-client compute chain id from seed]. *) +let compute_chain_id_from_seed ?endpoint client seed = + let* output = + spawn_compute_chain_id_from_seed ?endpoint client seed + |> Process.check_and_read_stdout + in + return (String.trim output) diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 090646ec5b370c19535e9f8c472c1dd16191c316..77f9ab43b3efee0f791d7433f55188fb2715773a 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -2387,3 +2387,19 @@ val spawn_config_init : ?protocol_constants:string -> t -> Process.t + +(** Run [tezos-client compute chain id from block hash]. *) +val compute_chain_id_from_block_hash : + ?endpoint:endpoint -> t -> string -> string Lwt.t + +(** Same as [compute_chain_id_from_block_hash], but do not wait for the process to exit. *) +val spawn_compute_chain_id_from_block_hash : + ?endpoint:endpoint -> t -> string -> Process.t + +(** Run [tezos-client compute chain id from seed]. *) +val compute_chain_id_from_seed : + ?endpoint:endpoint -> t -> string -> string Lwt.t + +(** Same as [compute_chain_id_from_seed], but do not wait for the process to exit. *) +val spawn_compute_chain_id_from_seed : + ?endpoint:endpoint -> t -> string -> Process.t diff --git a/tezt/tests/client_chain_id.ml b/tezt/tests/client_chain_id.ml new file mode 100644 index 0000000000000000000000000000000000000000..f463e6acf98a19826e50a8944bc116916e61d760 --- /dev/null +++ b/tezt/tests/client_chain_id.ml @@ -0,0 +1,54 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(* Testing + ------- + Component: Client / Chain ids + Invocation: dune exec tezt/tests/main.exe -- --file client_without_node.ml + Subject: Tests the [compute chain id] commands of octez-client +*) + +let test_chain_id () = + Test.register ~__FILE__ ~title:"Chain id" ~tags:["chain"; "id"] @@ fun () -> + Log.info "Chain id block hash" ; + let* client = Client.init () in + let block_hash = "BKyFui5WPY1n3e9aKF3qd2kGBKBtHu3rtm5miYFnUagJC1BdHTF" in + let* chain_id = Client.compute_chain_id_from_block_hash client block_hash in + Check.( + (chain_id = "NetXuwrXPL4VeX5") + string + ~__LOC__ + ~error_msg:"Expected %R, got %L") ; + Log.info "Chain id seed" ; + let seed = "choucroute" in + let* chain_id = Client.compute_chain_id_from_seed client seed in + Check.( + (chain_id = "NetXLGmPi3c5DXf") + string + ~__LOC__ + ~error_msg:"Expected %R, got %L") ; + unit + +let register_protocol_independent () = test_chain_id () diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 111249a2cf54ef0531ba62508a32f1492cc9c76c..40032087af08c78ea86c546e0a945a6126951481 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -46,6 +46,7 @@ let register_protocol_independent_tests () = Bootstrap.register_protocol_independent () ; Cli_tezos.register_protocol_independent () ; Client_keys.register_protocol_independent () ; + Client_chain_id.register_protocol_independent () ; Config.register () ; Demo_counter.register () ; Injection.register_protocol_independent () ;