From 40a6c3e3d97ad2abb5af6a8d688bb91856906641 Mon Sep 17 00:00:00 2001 From: YY Date: Fri, 16 Sep 2022 14:47:02 +0800 Subject: [PATCH 1/3] Tezt: add Client.hash_script --- tezt/lib_tezos/client.ml | 6 ++++++ tezt/lib_tezos/client.mli | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 454c0292f736..b21f3332f4d7 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -1301,6 +1301,12 @@ let register_global_constant ?wait ?burn_cap ~src ~value client = client_output | Some hash -> return hash +let spawn_hash_script ?hooks ~script client = + spawn_command ?hooks client ["hash"; "script"; script] + +let hash_script ?hooks ~script client = + spawn_hash_script ?hooks ~script client |> Process.check_and_read_stdout + let spawn_hash_data ?hooks ~data ~typ client = let cmd = ["hash"; "data"; data; "of"; "type"; typ] in spawn_command ?hooks client cmd diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index aa49b4cfe78e..d3c996c862af 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -1047,6 +1047,13 @@ val hash_data : val spawn_hash_data : ?hooks:Process.hooks -> data:string -> typ:string -> t -> Process.t +(** Run [tezos-client hash script ..]*) +val hash_script : ?hooks:Process_hooks.t -> script:string -> t -> string Lwt.t + +(** Same as [hash_script], but do not wait for the process to exit. *) +val spawn_hash_script : + ?hooks:Process_hooks.t -> script:string -> t -> Process.t + (** Run [tezos-client normalize data .. of type ...]*) val normalize_data : ?mode:normalize_mode -> -- GitLab From 79179b8900ea86d304c28a5bfbf07df127b71a09 Mon Sep 17 00:00:00 2001 From: YY Date: Fri, 16 Sep 2022 14:47:30 +0800 Subject: [PATCH 2/3] Tezt: add Bad_indentation Tezt: use Check instead of assert in BadIndentation Tezt: fix typo in BadIndentation Tezt: remove unnecessary logging --- tezt/tests/bad_indentation.ml | 115 ++++++++++++++++++++++++++++++++++ tezt/tests/main.ml | 1 + 2 files changed, 116 insertions(+) create mode 100644 tezt/tests/bad_indentation.ml diff --git a/tezt/tests/bad_indentation.ml b/tezt/tests/bad_indentation.ml new file mode 100644 index 000000000000..67eebecfed4a --- /dev/null +++ b/tezt/tests/bad_indentation.ml @@ -0,0 +1,115 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Marigold *) +(* *) +(* 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 + ------- + Components: Michelson + Invocation: dune exec tezt/tests/main.exe -- --file bad_indentation.ml + Subject: Tests for the "hash script" and "convert script" commands on + badly-indented scripts +*) + +let badly_indented_script = + {| +parameter string; + storage string; + code {CAR; NIL operation; PAIR} +|} + +let script_hash = "exprv8K6ceBpFH5SFjQm4BRYSLJCHQBFeQU6BFTdvQSRPaPkzdLyAL" + +let test_bad_indentation_ill_typed = + Protocol.register_test + ~__FILE__ + ~title:"Bad indentation contract is ill-typed" + ~tags:["client"; "michelson"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let process = + Client.spawn_typecheck_script ~script:badly_indented_script client + in + Process.check_error ~exit_code:1 ~msg:(rex "syntax error in program") process + +let test_bad_indentation_hash = + Protocol.register_test + ~__FILE__ + ~title:"Bad indentation contract hash is expected" + ~tags:["client"; "michelson"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* received = Client.hash_script ~script:badly_indented_script client in + let returned_hash = String.trim received in + Check.( + (returned_hash = script_hash) + string + ~__LOC__ + ~error_msg:"Expected script hash %R, got %L") ; + unit + +let test_formatted_typechecks = + Protocol.register_test + ~__FILE__ + ~title:"Formatted bad indentation contract is well-typed" + ~tags:["client"; "michelson"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* formatted_script = + Client.convert_script + ~script:badly_indented_script + ~src_format:`Michelson + ~dst_format:`Michelson + client + in + let* _ = Client.typecheck_script ~script:formatted_script client in + unit + +let test_formatted_hash = + Protocol.register_test + ~__FILE__ + ~title:"Formatted bad indentation contract hash is expected" + ~tags:["client"; "michelson"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* formatted_script = + Client.convert_script + ~script:badly_indented_script + ~src_format:`Michelson + ~dst_format:`Michelson + client + in + let* received = Client.hash_script ~script:formatted_script client in + let returned_hash = String.trim received in + Check.( + (returned_hash = script_hash) + string + ~__LOC__ + ~error_msg:"Expected script hash %R, got %L") ; + unit + +let register ~protocols = + test_bad_indentation_ill_typed protocols ; + test_bad_indentation_hash protocols ; + test_formatted_typechecks protocols ; + test_formatted_hash protocols diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index b6817b8eea94..361fc61fc1e1 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -85,6 +85,7 @@ let register_protocol_migration_tests () = let register_protocol_agnostic_tests () = (* Tests that are relatively protocol-agnostic. We can run them on all protocols, or only one if the CI would be too slow. *) + Bad_indentation.register ~protocols ; Baker_test.register ~protocols:[Alpha] ; Baking.register ~protocols ; Baking.register_operations_pool ~protocols:[Jakarta; Kathmandu; Alpha] ; -- GitLab From 90f2e847b0426290bb5487bf440b943708b33320 Mon Sep 17 00:00:00 2001 From: YY Date: Fri, 16 Sep 2022 18:28:54 +0800 Subject: [PATCH 3/3] PyTest: remove TestBadIndentation --- .../contracts_013/ill_typed/badly_indented.tz | 3 -- .../contracts_014/ill_typed/badly_indented.tz | 3 -- .../ill_typed/badly_indented.tz | 3 -- tests_python/tests_013/test_contract.py | 33 ------------------- tests_python/tests_014/test_contract.py | 33 ------------------- tests_python/tests_alpha/test_contract.py | 33 ------------------- 6 files changed, 108 deletions(-) delete mode 100644 tests_python/contracts_013/ill_typed/badly_indented.tz delete mode 100644 tests_python/contracts_014/ill_typed/badly_indented.tz delete mode 100644 tests_python/contracts_alpha/ill_typed/badly_indented.tz diff --git a/tests_python/contracts_013/ill_typed/badly_indented.tz b/tests_python/contracts_013/ill_typed/badly_indented.tz deleted file mode 100644 index 0fc54663a9f9..000000000000 --- a/tests_python/contracts_013/ill_typed/badly_indented.tz +++ /dev/null @@ -1,3 +0,0 @@ -parameter string; - storage string; - code {CAR; NIL operation; PAIR} diff --git a/tests_python/contracts_014/ill_typed/badly_indented.tz b/tests_python/contracts_014/ill_typed/badly_indented.tz deleted file mode 100644 index 0fc54663a9f9..000000000000 --- a/tests_python/contracts_014/ill_typed/badly_indented.tz +++ /dev/null @@ -1,3 +0,0 @@ -parameter string; - storage string; - code {CAR; NIL operation; PAIR} diff --git a/tests_python/contracts_alpha/ill_typed/badly_indented.tz b/tests_python/contracts_alpha/ill_typed/badly_indented.tz deleted file mode 100644 index 0fc54663a9f9..000000000000 --- a/tests_python/contracts_alpha/ill_typed/badly_indented.tz +++ /dev/null @@ -1,3 +0,0 @@ -parameter string; - storage string; - code {CAR; NIL operation; PAIR} diff --git a/tests_python/tests_013/test_contract.py b/tests_python/tests_013/test_contract.py index a004f160c78d..7de19a515709 100644 --- a/tests_python/tests_013/test_contract.py +++ b/tests_python/tests_013/test_contract.py @@ -2094,39 +2094,6 @@ class TestTZIP4View: assert const_view_res.result == "5\n" and add_view_res.result == "4\n" -@pytest.mark.contract -@pytest.mark.incremental -class TestBadIndentation: - """Tests for the "hash script" and "convert script" commands on - badly-indented scripts.""" - - BADLY_INDENTED = os.path.join(ILLTYPED_CONTRACT_PATH, 'badly_indented.tz') - - SCRIPT_HASH = "exprv8K6ceBpFH5SFjQm4BRYSLJCHQBFeQU6BFTdvQSRPaPkzdLyAL" - - def test_bad_indentation_ill_typed(self, client): - with utils.assert_run_failure('syntax error in program'): - client.typecheck(self.BADLY_INDENTED) - - def test_bad_indentation_hash(self, client): - assert client.hash_script([self.BADLY_INDENTED]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatting(self, client, session): - session['formatted_script'] = client.convert_script( - self.BADLY_INDENTED, 'Michelson', 'Michelson' - ) - - def test_formatted_hash(self, client, session): - assert client.hash_script([session['formatted_script']]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatted_typechecks(self, client, session): - client.typecheck(session['formatted_script'], file=False) - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index 6dbec261d24a..973491eb63f0 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -2089,39 +2089,6 @@ class TestTZIP4View: assert const_view_res.result == "5\n" and add_view_res.result == "4\n" -@pytest.mark.contract -@pytest.mark.incremental -class TestBadIndentation: - """Tests for the "hash script" and "convert script" commands on - badly-indented scripts.""" - - BADLY_INDENTED = os.path.join(ILLTYPED_CONTRACT_PATH, 'badly_indented.tz') - - SCRIPT_HASH = "exprv8K6ceBpFH5SFjQm4BRYSLJCHQBFeQU6BFTdvQSRPaPkzdLyAL" - - def test_bad_indentation_ill_typed(self, client): - with utils.assert_run_failure('syntax error in program'): - client.typecheck(self.BADLY_INDENTED) - - def test_bad_indentation_hash(self, client): - assert client.hash_script([self.BADLY_INDENTED]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatting(self, client, session): - session['formatted_script'] = client.convert_script( - self.BADLY_INDENTED, 'Michelson', 'Michelson' - ) - - def test_formatted_hash(self, client, session): - assert client.hash_script([session['formatted_script']]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatted_typechecks(self, client, session): - client.typecheck(session['formatted_script'], file=False) - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index 36ca7bc4df59..99f39557a1a4 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -2089,39 +2089,6 @@ class TestTZIP4View: assert const_view_res.result == "5\n" and add_view_res.result == "4\n" -@pytest.mark.contract -@pytest.mark.incremental -class TestBadIndentation: - """Tests for the "hash script" and "convert script" commands on - badly-indented scripts.""" - - BADLY_INDENTED = os.path.join(ILLTYPED_CONTRACT_PATH, 'badly_indented.tz') - - SCRIPT_HASH = "exprv8K6ceBpFH5SFjQm4BRYSLJCHQBFeQU6BFTdvQSRPaPkzdLyAL" - - def test_bad_indentation_ill_typed(self, client): - with utils.assert_run_failure('syntax error in program'): - client.typecheck(self.BADLY_INDENTED) - - def test_bad_indentation_hash(self, client): - assert client.hash_script([self.BADLY_INDENTED]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatting(self, client, session): - session['formatted_script'] = client.convert_script( - self.BADLY_INDENTED, 'Michelson', 'Michelson' - ) - - def test_formatted_hash(self, client, session): - assert client.hash_script([session['formatted_script']]) == [ - (self.SCRIPT_HASH, None) - ] - - def test_formatted_typechecks(self, client, session): - client.typecheck(session['formatted_script'], file=False) - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: -- GitLab