diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index f6ab93b5f6068a07638ca39189a7ff248448ddf2..9f0976f439eac2aaa1373b9f37935074e0d410a2 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 f6ab93b5f6068a07638ca39189a7ff248448ddf2..9f0976f439eac2aaa1373b9f37935074e0d410a2 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 f6ab93b5f6068a07638ca39189a7ff248448ddf2..9f0976f439eac2aaa1373b9f37935074e0d410a2 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 diff --git a/tezt/tests/bad_indentation.ml b/tezt/tests/bad_indentation.ml index 67eebecfed4a0f82f0dff85ebdf28efcbbad00ba..75ef68f3ce4b7d917c28b40b5df18c9083534c8f 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 270adf5168170fa8535a754672ab7f02733072a1..9a13bdb58a6bbd96bac2fb367089637aa9bb943e 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 c1f576ef37e3f7040785d41d9bed241a1b394d3f..8879fa1d235913767f452f7f334abba68383cd07 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/main.ml b/tezt/tests/main.ml index 0cd26c130186e936b52ed69a3da43964362829d5..24afde0a94526c1b629f37307c3efdd99a9d2079 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 0000000000000000000000000000000000000000..c6e77e024b97ac64ea61b159c210018058809cc1 --- /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 diff --git a/tezt/tests/self_address_transfer.ml b/tezt/tests/self_address_transfer.ml index fa67da91e48ae6b0abd8310a0d80224177acc852..5382cde39c5c724db429551b5439f2b3e8acc3ad 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 dab6b63d15220785cb578959ceb058888824e52d..7eea0a0bbbabd4052d90cf09434d5291a22403c1 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 c120565d5533035c6ed09b0f355bcdf7a602e70d..6550f3e42ed9b86baaa2596e9c5ed203fb11638f 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 *)