From e314fd4b3b5f19e3912ffdfa41e4eaf13b4658d5 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Sat, 3 Dec 2022 18:20:39 +0800 Subject: [PATCH] Test: move contract non-regression tests to tezt --- tests_python/tests_014/test_contract.py | 44 -------- tests_python/tests_015/test_contract.py | 44 -------- tests_python/tests_alpha/test_contract.py | 44 -------- tezt/tests/contract_non_regressions.ml | 131 ++++++++++++++++++++++ tezt/tests/main.ml | 1 + 5 files changed, 132 insertions(+), 132 deletions(-) create mode 100644 tezt/tests/contract_non_regressions.ml diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index b64658f7666a..6fcf5d5c66e0 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1027,50 +1027,6 @@ class TestChainId: utils.bake(client, bake_for='bootstrap5') -@pytest.mark.incremental -@pytest.mark.contract -class TestNonRegression: - """Test contract-related non-regressions""" - - def test_issue_242_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_262.tz') - originate(client, session, path, 'Unit', 1) - - def test_issue_242_assert_balance(self, client: Client): - assert client.get_balance('bug_262') == 1 - - def test_issue_843(self, client: Client, session: dict): - """Regression test for the following bug: - https://gitlab.com/tezos/tezos/-/issues/843 - - This test checks that before origination the script, storage, - and the lambdas inside the storage are all normalized. To test - this we define them in readable mode and compare the storage - size of the origination operations when the readable script - and storage are used directly and when they are first - normalized to optimized format before origination. - """ - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_843.tz') - addr1 = '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' - op1 = originate( - client, - session, - path, - f'Pair {addr1} {{PUSH address {addr1}; DROP}}', - 0, - ) - normalized_script = client.normalize_script(path, mode='Optimized') - addr2 = client.normalize(addr1, 'address', mode='Optimized').strip() - op2 = originate( - client, - session, - normalized_script, - f'Pair {addr2} {{PUSH address {addr2}; DROP}}', - 0, - ) - assert op1.storage_size == op2.storage_size - - @pytest.mark.contract class TestScriptHashMultiple: """Test octez-client hash script with diffent number and type of diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index b64658f7666a..6fcf5d5c66e0 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1027,50 +1027,6 @@ class TestChainId: utils.bake(client, bake_for='bootstrap5') -@pytest.mark.incremental -@pytest.mark.contract -class TestNonRegression: - """Test contract-related non-regressions""" - - def test_issue_242_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_262.tz') - originate(client, session, path, 'Unit', 1) - - def test_issue_242_assert_balance(self, client: Client): - assert client.get_balance('bug_262') == 1 - - def test_issue_843(self, client: Client, session: dict): - """Regression test for the following bug: - https://gitlab.com/tezos/tezos/-/issues/843 - - This test checks that before origination the script, storage, - and the lambdas inside the storage are all normalized. To test - this we define them in readable mode and compare the storage - size of the origination operations when the readable script - and storage are used directly and when they are first - normalized to optimized format before origination. - """ - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_843.tz') - addr1 = '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' - op1 = originate( - client, - session, - path, - f'Pair {addr1} {{PUSH address {addr1}; DROP}}', - 0, - ) - normalized_script = client.normalize_script(path, mode='Optimized') - addr2 = client.normalize(addr1, 'address', mode='Optimized').strip() - op2 = originate( - client, - session, - normalized_script, - f'Pair {addr2} {{PUSH address {addr2}; DROP}}', - 0, - ) - assert op1.storage_size == op2.storage_size - - @pytest.mark.contract class TestScriptHashMultiple: """Test octez-client hash script with diffent number and type of diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index b64658f7666a..6fcf5d5c66e0 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1027,50 +1027,6 @@ class TestChainId: utils.bake(client, bake_for='bootstrap5') -@pytest.mark.incremental -@pytest.mark.contract -class TestNonRegression: - """Test contract-related non-regressions""" - - def test_issue_242_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_262.tz') - originate(client, session, path, 'Unit', 1) - - def test_issue_242_assert_balance(self, client: Client): - assert client.get_balance('bug_262') == 1 - - def test_issue_843(self, client: Client, session: dict): - """Regression test for the following bug: - https://gitlab.com/tezos/tezos/-/issues/843 - - This test checks that before origination the script, storage, - and the lambdas inside the storage are all normalized. To test - this we define them in readable mode and compare the storage - size of the origination operations when the readable script - and storage are used directly and when they are first - normalized to optimized format before origination. - """ - path = os.path.join(CONTRACT_PATH, 'non_regression', 'bug_843.tz') - addr1 = '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' - op1 = originate( - client, - session, - path, - f'Pair {addr1} {{PUSH address {addr1}; DROP}}', - 0, - ) - normalized_script = client.normalize_script(path, mode='Optimized') - addr2 = client.normalize(addr1, 'address', mode='Optimized').strip() - op2 = originate( - client, - session, - normalized_script, - f'Pair {addr2} {{PUSH address {addr2}; DROP}}', - 0, - ) - assert op1.storage_size == op2.storage_size - - @pytest.mark.contract class TestScriptHashMultiple: """Test octez-client hash script with diffent number and type of diff --git a/tezt/tests/contract_non_regressions.ml b/tezt/tests/contract_non_regressions.ml new file mode 100644 index 000000000000..2f5d0d404cc2 --- /dev/null +++ b/tezt/tests/contract_non_regressions.ml @@ -0,0 +1,131 @@ +(*****************************************************************************) +(* *) +(* 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: Michelson + Invocation: dune exec tezt/tests/main.exe -- --file contract_non_regressions.ml + Subject: Test contract-related non-regressions +*) + +let contract_path protocol kind contract = + sf + "tests_python/contracts_%s/%s/%s" + (match protocol with + | Protocol.Alpha -> "alpha" + | _ -> sf "%03d" @@ Protocol.number protocol) + kind + contract + +(* Normally "--base-dir" would appear in regression logs. However, since + it is a different dir on every run, we need to mask it in regression + logs so that it doesn't cause false differences. *) +let hooks = Tezos_regression.hooks + +let register262 = + Protocol.register_test + ~__FILE__ + ~title:"Contract-related non-regressions, Issue 262" + ~tags:["client"; "michelson"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* contract = + Client.originate_contract + ~hooks + ~burn_cap:Tez.one + ~alias:"contract" + ~amount:Tez.one + ~src:Constant.bootstrap1.alias + ~prg:(sf "file:%s" @@ contract_path protocol "non_regression" "bug_262.tz") + ~init:"Unit" + client + in + let* balance = Client.get_balance_for ~account:contract client in + Check.(balance = Tez.one) + ~__LOC__ + Tez.typ + ~error_msg:"expected balance %R, got %L" ; + unit + +let register843 = + Protocol.register_test + ~__FILE__ + ~title:"Contract-related non-regressions, Issue 843" + ~tags:["client"; "michelson"] + ~supports:(Protocol.From_protocol 015) + @@ fun protocol -> + (* https://gitlab.com/tezos/tezos/-/issues/843 + + This test checks that before origination the script, storage, and + the lambdas inside the storage are all normalized. To test this + we define them in readable mode and compare the storage size of + the origination operations when the readable script and storage + are used directly and when they are first normalized to optimized + format before origination. *) + let* client = Client.init_mockup ~protocol () in + let addr = {|"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"|} in + let bug843 = contract_path protocol "non_regression" "bug_843.tz" in + let* contract1 = + Client.originate_contract + ~hooks + ~burn_cap:Tez.one + ~alias:"contract1" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg:(sf "file:%s" bug843) + ~init:(sf "Pair %s {PUSH address %s; DROP}" addr addr) + client + in + let* normalized_script = + Client.normalize_script ~script:(read_file bug843) ~mode:Optimized client + in + let* normalized_addr = + Client.normalize_data ~data:addr ~typ:"address" ~mode:Optimized client + in + let normalized_addr = String.trim normalized_addr in + let* contract2 = + Client.originate_contract + ~hooks + ~burn_cap:Tez.one + ~alias:"contract2" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg:normalized_script + ~init: + (sf "Pair %s {PUSH address %s; DROP}" normalized_addr normalized_addr) + client + in + let* storage_size1 = Client.used_storage_space ~contract:contract1 client in + let* storage_size2 = Client.used_storage_space ~contract:contract2 client in + Check.(storage_size1 = storage_size2) + ~__LOC__ + Check.string + ~error_msg:"expected equal storage size, got %L <> %R" ; + unit + +let register protocols = + register262 protocols ; + register843 protocols diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index c51119279129..eef13e70d441 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -112,6 +112,7 @@ let register_protocol_tests_that_use_supports_correctly () = Contract_entrypoints.register ~protocols ; Contract_hash_fun.register ~protocols ; Contract_hash_with_origination.register ~protocols ; + Contract_non_regressions.register protocols ; Contract_opcodes.register ~protocols ; Contract_typecheck.register ~protocols ; Contract_mini_scenarios.register ~protocols ; -- GitLab