From bec93eeb91f7115f01545078786d240ef4757e63 Mon Sep 17 00:00:00 2001 From: lin Date: Mon, 17 Oct 2022 22:10:55 +0900 Subject: [PATCH 1/3] Tezt: Add order_in_top_level.ml --- tezt/tests/main.ml | 1 + tezt/tests/order_in_top_level.ml | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tezt/tests/order_in_top_level.ml diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 0cd26c130186..24afde0a9452 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -127,6 +127,7 @@ let register_protocol_tests_that_use_supports_correctly () = Node_event_level.register ~protocols ; Normalize.register ~protocols ; Operation_validation.register ~protocols ; + Order_in_top_level.register ~protocols ; P2p.register ~protocols ; Precheck.register ~protocols ; Prevalidator.register ~protocols ; diff --git a/tezt/tests/order_in_top_level.ml b/tezt/tests/order_in_top_level.ml new file mode 100644 index 000000000000..c6e77e024b97 --- /dev/null +++ b/tezt/tests/order_in_top_level.ml @@ -0,0 +1,62 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* 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 + ------- + Component: Script + Invocation: dune exec tezt/tests/main.exe -- --file order_in_top_level.ml + Subject: Test that the storage, code, and parameter sections can appear in any order in a contract script. +*) + +(** [interleave x l] inserts [x] into all positions of [l]. + For example, [interleave 1 [2; 3]] will return [[[1; 2; 3]; [2; 1; 3]; [2; 3; 1]]]. *) +let rec interleave (x : 'a) (l : 'a list) : 'a list list = + match l with + | [] -> [[x]] + | h :: t -> (x :: h :: t) :: (interleave x t |> List.map (fun t' -> h :: t')) + +(** [permutations l] returns all permutations of [l] *) +let rec permutations : 'a list -> 'a list list = function + | [] -> [[]] + | x :: xs -> permutations xs |> List.map (interleave x) |> List.flatten + +let test_order_in_top_level = + Protocol.register_test + ~__FILE__ + ~title:"Order in top level of the script does not matter." + ~tags:["client"; "script"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let top_level_elements = + ["parameter nat"; "storage unit"; "code { CDR; NIL operation; PAIR }"] + in + permutations top_level_elements + |> Lwt_list.iter_s @@ fun elements -> + let script = String.concat ";\n" elements in + let* _ = Client.typecheck_script client ~script in + unit + +let register ~protocols = test_order_in_top_level protocols -- GitLab From 6f9e344b24ccd2246db0aac72b564349dea95ef3 Mon Sep 17 00:00:00 2001 From: lin Date: Mon, 17 Oct 2022 22:12:13 +0900 Subject: [PATCH 2/3] Pytest: Remove TestOrderInTopLevelDoesNotMatter --- tests_python/tests_014/test_contract.py | 25 ----------------------- tests_python/tests_015/test_contract.py | 25 ----------------------- tests_python/tests_alpha/test_contract.py | 25 ----------------------- 3 files changed, 75 deletions(-) diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index f6ab93b5f606..9f0976f439ea 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1,6 +1,5 @@ import os import re -import itertools from typing import List, Union, Any import pytest @@ -1637,30 +1636,6 @@ class TestBadAnnotation: assert res.storage == 'None' -@pytest.mark.contract -class TestOrderInTopLevelDoesNotMatter: - @pytest.fixture - def contract_splitted_in_top_level_elements(self): - return [ - "parameter nat", - "storage unit", - "code { CDR; NIL operation; PAIR }", - ] - - def test_shuffle( - self, client: Client, contract_splitted_in_top_level_elements - ): - """ - Test that the storage, code, and parameter sections can appear in any - order in a contract script. - """ - for shuffled_list in itertools.permutations( - contract_splitted_in_top_level_elements - ): - contract = ";\n".join(shuffled_list) - client.typecheck(contract, file=False) - - @pytest.mark.slow @pytest.mark.contract @pytest.mark.regression diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index f6ab93b5f606..9f0976f439ea 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1,6 +1,5 @@ import os import re -import itertools from typing import List, Union, Any import pytest @@ -1637,30 +1636,6 @@ class TestBadAnnotation: assert res.storage == 'None' -@pytest.mark.contract -class TestOrderInTopLevelDoesNotMatter: - @pytest.fixture - def contract_splitted_in_top_level_elements(self): - return [ - "parameter nat", - "storage unit", - "code { CDR; NIL operation; PAIR }", - ] - - def test_shuffle( - self, client: Client, contract_splitted_in_top_level_elements - ): - """ - Test that the storage, code, and parameter sections can appear in any - order in a contract script. - """ - for shuffled_list in itertools.permutations( - contract_splitted_in_top_level_elements - ): - contract = ";\n".join(shuffled_list) - client.typecheck(contract, file=False) - - @pytest.mark.slow @pytest.mark.contract @pytest.mark.regression diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index f6ab93b5f606..9f0976f439ea 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1,6 +1,5 @@ import os import re -import itertools from typing import List, Union, Any import pytest @@ -1637,30 +1636,6 @@ class TestBadAnnotation: assert res.storage == 'None' -@pytest.mark.contract -class TestOrderInTopLevelDoesNotMatter: - @pytest.fixture - def contract_splitted_in_top_level_elements(self): - return [ - "parameter nat", - "storage unit", - "code { CDR; NIL operation; PAIR }", - ] - - def test_shuffle( - self, client: Client, contract_splitted_in_top_level_elements - ): - """ - Test that the storage, code, and parameter sections can appear in any - order in a contract script. - """ - for shuffled_list in itertools.permutations( - contract_splitted_in_top_level_elements - ): - contract = ";\n".join(shuffled_list) - client.typecheck(contract, file=False) - - @pytest.mark.slow @pytest.mark.contract @pytest.mark.regression -- GitLab From 470ca007639eb6757f7422769e0ebf5bada186a4 Mon Sep 17 00:00:00 2001 From: lin Date: Thu, 20 Oct 2022 22:50:55 +0900 Subject: [PATCH 3/3] Tezt: Fix copyright for tests migrated by Marigold The original pytests for these migrated tests were written by Nomadic Labs. We should retain the copyright to reflect this. --- tezt/tests/bad_indentation.ml | 1 + tezt/tests/big_map_arity.ml | 1 + tezt/tests/create_contract.ml | 1 + tezt/tests/self_address_transfer.ml | 1 + tezt/tests/tickets.ml | 1 + tezt/tests/tzip4_view.ml | 1 + 6 files changed, 6 insertions(+) diff --git a/tezt/tests/bad_indentation.ml b/tezt/tests/bad_indentation.ml index 67eebecfed4a..75ef68f3ce4b 100644 --- a/tezt/tests/bad_indentation.ml +++ b/tezt/tests/bad_indentation.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) diff --git a/tezt/tests/big_map_arity.ml b/tezt/tests/big_map_arity.ml index 270adf516817..9a13bdb58a6b 100644 --- a/tezt/tests/big_map_arity.ml +++ b/tezt/tests/big_map_arity.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) diff --git a/tezt/tests/create_contract.ml b/tezt/tests/create_contract.ml index c1f576ef37e3..8879fa1d2359 100644 --- a/tezt/tests/create_contract.ml +++ b/tezt/tests/create_contract.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) diff --git a/tezt/tests/self_address_transfer.ml b/tezt/tests/self_address_transfer.ml index fa67da91e48a..5382cde39c5c 100644 --- a/tezt/tests/self_address_transfer.ml +++ b/tezt/tests/self_address_transfer.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) diff --git a/tezt/tests/tickets.ml b/tezt/tests/tickets.ml index dab6b63d1522..7eea0a0bbbab 100644 --- a/tezt/tests/tickets.ml +++ b/tezt/tests/tickets.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) diff --git a/tezt/tests/tzip4_view.ml b/tezt/tests/tzip4_view.ml index c120565d5533..6550f3e42ed9 100644 --- a/tezt/tests/tzip4_view.ml +++ b/tezt/tests/tzip4_view.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) (* Copyright (c) 2022 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) -- GitLab