From 59a66d5a99b2c9a94600c8cabc78a10cde8d7014 Mon Sep 17 00:00:00 2001 From: lykimq Date: Thu, 10 Nov 2022 09:18:46 +0700 Subject: [PATCH 1/4] Michelson/Tezt: add bad annotation test --- tezt/tests/bad_annot.ml | 64 +++++++++++++++++++++++++++++++++++++++++ tezt/tests/main.ml | 1 + 2 files changed, 65 insertions(+) create mode 100644 tezt/tests/bad_annot.ml diff --git a/tezt/tests/bad_annot.ml b/tezt/tests/bad_annot.ml new file mode 100644 index 000000000000..0e7f680c63b8 --- /dev/null +++ b/tezt/tests/bad_annot.ml @@ -0,0 +1,64 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 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 bad_annot.ml + Subject: Tests the UNPACK instruction on ill-annotated input +*) + +let test_bad_annot client protocol () = + (* This was produced by running "octez-client hash data '{ UNIT + ; PAIR ; CAR %faa }' of type 'lambda unit unit'" and + replacing the two last bytes (that correspond to the two + 'a's at the end of the annotation) by the 0xff byte which is + not a valid UTF8-encoding of a string *) + let input = "0x05020000000e034f03420416000000042566ffff" in + let prg = + sf + "file:./tests_python/contracts_%s/non_regression/bad_annot_contract.tz" + (match protocol with + | Protocol.Alpha -> "alpha" + | _ -> sf "%03d" @@ Protocol.number protocol) + in + let* storage = Client.run_script ~prg ~storage:"None" ~input client in + Check.( + ("None" = storage) ~__LOC__ string ~error_msg:"Expected result %R, got %L") ; + unit + +let register ~protocols = + List.iter + (fun (title, test_function) -> + Protocol.register_test + ~__FILE__ + ~title + ~tags:["client"; "michelson"] + (fun protocol -> + let* client = Client.init_mockup ~protocol () in + test_function client protocol ()) + protocols) + [("Test bad annotation", test_bad_annot)] diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 4307dd688474..60a2dad1b47e 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -93,6 +93,7 @@ let register_older_protocol_migration_tests () = Then we could remove the [~protocols] argument from all register functions. *) let register_protocol_tests_that_use_supports_correctly () = let protocols = Protocol.all in + Bad_annot.register ~protocols ; Bad_indentation.register ~protocols ; Baker_test.register ~protocols ; Baking.register ~protocols ; -- GitLab From c2d41b56dcfb0b357390f68215de0e4c01a47ec0 Mon Sep 17 00:00:00 2001 From: lykimq Date: Thu, 10 Nov 2022 09:19:50 +0700 Subject: [PATCH 2/4] Michelson/Python: add contract bad_annot_contract.tz --- .../contracts_014/non_regression/bad_annot_contract.tz | 6 ++++++ .../contracts_015/non_regression/bad_annot_contract.tz | 6 ++++++ .../contracts_alpha/non_regression/bad_annot_contract.tz | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 tests_python/contracts_014/non_regression/bad_annot_contract.tz create mode 100644 tests_python/contracts_015/non_regression/bad_annot_contract.tz create mode 100644 tests_python/contracts_alpha/non_regression/bad_annot_contract.tz diff --git a/tests_python/contracts_014/non_regression/bad_annot_contract.tz b/tests_python/contracts_014/non_regression/bad_annot_contract.tz new file mode 100644 index 000000000000..cec7bccd1adf --- /dev/null +++ b/tests_python/contracts_014/non_regression/bad_annot_contract.tz @@ -0,0 +1,6 @@ +parameter bytes; +storage (option (lambda unit unit)); +code { CAR; + UNPACK (lambda unit unit); + NIL operation; + PAIR } diff --git a/tests_python/contracts_015/non_regression/bad_annot_contract.tz b/tests_python/contracts_015/non_regression/bad_annot_contract.tz new file mode 100644 index 000000000000..cec7bccd1adf --- /dev/null +++ b/tests_python/contracts_015/non_regression/bad_annot_contract.tz @@ -0,0 +1,6 @@ +parameter bytes; +storage (option (lambda unit unit)); +code { CAR; + UNPACK (lambda unit unit); + NIL operation; + PAIR } diff --git a/tests_python/contracts_alpha/non_regression/bad_annot_contract.tz b/tests_python/contracts_alpha/non_regression/bad_annot_contract.tz new file mode 100644 index 000000000000..cec7bccd1adf --- /dev/null +++ b/tests_python/contracts_alpha/non_regression/bad_annot_contract.tz @@ -0,0 +1,6 @@ +parameter bytes; +storage (option (lambda unit unit)); +code { CAR; + UNPACK (lambda unit unit); + NIL operation; + PAIR } -- GitLab From 823c4758dd21710542c1cc3429ae7b2ed3c79a64 Mon Sep 17 00:00:00 2001 From: lykimq Date: Thu, 10 Nov 2022 09:21:07 +0700 Subject: [PATCH 3/4] Michelson/Python: run regression for added contracts --- ...tract_hash[client_regtest_custom_scrubber0].out | 1 + ...heck[non_regression--bad_annot_contract.tz].out | 14 ++++++++++++++ ...tract_hash[client_regtest_custom_scrubber0].out | 1 + ...heck[non_regression--bad_annot_contract.tz].out | 14 ++++++++++++++ ...tract_hash[client_regtest_custom_scrubber0].out | 1 + ...heck[non_regression--bad_annot_contract.tz].out | 14 ++++++++++++++ 6 files changed, 45 insertions(+) create mode 100644 tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out create mode 100644 tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out create mode 100644 tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out diff --git a/tests_python/tests_014/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out b/tests_python/tests_014/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out index b8bff943b82b..12208dda027f 100644 --- a/tests_python/tests_014/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out +++ b/tests_python/tests_014/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out @@ -104,6 +104,7 @@ exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scen expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz exprvKm5t6a6LL2d3HjvRiJumGrGei24aRXscJk3zB1hs516Ju4oMZ [CONTRACT_PATH]/mini_scenarios/xcat_dapp.tz +exprtyJrKmrcvMroXNvbNSJr4hrWcLqa6QHmKSSJLMNqe1nueq1MSt [CONTRACT_PATH]/non_regression/bad_annot_contract.tz exprucvy7NUDPu2yTWEA6WVsusEZgGRmU1WpVzrFnNZV7m2H8BVysF [CONTRACT_PATH]/non_regression/bug_262.tz exprumT8doqCpoTqPAuJa8dsnrC7giaz6aGnMkJDF9kg8j8mBEafAC [CONTRACT_PATH]/non_regression/bug_843.tz exprv3FvpUYzomvhmzxsQyuR1katpswNnicQZB4jA5uec3MERXk1cB [CONTRACT_PATH]/non_regression/pairk_annot.tz diff --git a/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out b/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out new file mode 100644 index 000000000000..60237fed1dd0 --- /dev/null +++ b/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out @@ -0,0 +1,14 @@ +tests_014/test_contract.py::TestTypecheck::test_typecheck[non_regression/bad_annot_contract.tz] + +Well typed +Gas remaining: 1039996.681 units remaining +{ parameter bytes ; + storage (option (lambda unit unit)) ; + code { CAR + /* [ bytes ] */ ; + UNPACK (lambda unit unit) + /* [ option (lambda unit unit) ] */ ; + NIL operation + /* [ list operation : option (lambda unit unit) ] */ ; + PAIR + /* [ pair (list operation) (option (lambda unit unit)) ] */ } } diff --git a/tests_python/tests_015/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out b/tests_python/tests_015/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out index 2bd065498cfc..f99adaf18db0 100644 --- a/tests_python/tests_015/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out +++ b/tests_python/tests_015/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out @@ -108,6 +108,7 @@ exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scen expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz exprvKm5t6a6LL2d3HjvRiJumGrGei24aRXscJk3zB1hs516Ju4oMZ [CONTRACT_PATH]/mini_scenarios/xcat_dapp.tz +exprtyJrKmrcvMroXNvbNSJr4hrWcLqa6QHmKSSJLMNqe1nueq1MSt [CONTRACT_PATH]/non_regression/bad_annot_contract.tz exprucvy7NUDPu2yTWEA6WVsusEZgGRmU1WpVzrFnNZV7m2H8BVysF [CONTRACT_PATH]/non_regression/bug_262.tz exprumT8doqCpoTqPAuJa8dsnrC7giaz6aGnMkJDF9kg8j8mBEafAC [CONTRACT_PATH]/non_regression/bug_843.tz exprv3FvpUYzomvhmzxsQyuR1katpswNnicQZB4jA5uec3MERXk1cB [CONTRACT_PATH]/non_regression/pairk_annot.tz diff --git a/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out b/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out new file mode 100644 index 000000000000..92e763a15719 --- /dev/null +++ b/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out @@ -0,0 +1,14 @@ +tests_015/test_contract.py::TestTypecheck::test_typecheck[non_regression/bad_annot_contract.tz] + +Well typed +Gas remaining: 1039996.681 units remaining +{ parameter bytes ; + storage (option (lambda unit unit)) ; + code { CAR + /* [ bytes ] */ ; + UNPACK (lambda unit unit) + /* [ option (lambda unit unit) ] */ ; + NIL operation + /* [ list operation : option (lambda unit unit) ] */ ; + PAIR + /* [ pair (list operation) (option (lambda unit unit)) ] */ } } diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out index 9d31db447ee8..20ad6c7671bf 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out @@ -106,6 +106,7 @@ exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scen expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz exprvKm5t6a6LL2d3HjvRiJumGrGei24aRXscJk3zB1hs516Ju4oMZ [CONTRACT_PATH]/mini_scenarios/xcat_dapp.tz +exprtyJrKmrcvMroXNvbNSJr4hrWcLqa6QHmKSSJLMNqe1nueq1MSt [CONTRACT_PATH]/non_regression/bad_annot_contract.tz exprucvy7NUDPu2yTWEA6WVsusEZgGRmU1WpVzrFnNZV7m2H8BVysF [CONTRACT_PATH]/non_regression/bug_262.tz exprumT8doqCpoTqPAuJa8dsnrC7giaz6aGnMkJDF9kg8j8mBEafAC [CONTRACT_PATH]/non_regression/bug_843.tz exprv3FvpUYzomvhmzxsQyuR1katpswNnicQZB4jA5uec3MERXk1cB [CONTRACT_PATH]/non_regression/pairk_annot.tz diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out new file mode 100644 index 000000000000..a48ddfdce697 --- /dev/null +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[non_regression--bad_annot_contract.tz].out @@ -0,0 +1,14 @@ +tests_alpha/test_contract.py::TestTypecheck::test_typecheck[non_regression/bad_annot_contract.tz] + +Well typed +Gas remaining: 1039996.681 units remaining +{ parameter bytes ; + storage (option (lambda unit unit)) ; + code { CAR + /* [ bytes ] */ ; + UNPACK (lambda unit unit) + /* [ option (lambda unit unit) ] */ ; + NIL operation + /* [ list operation : option (lambda unit unit) ] */ ; + PAIR + /* [ pair (list operation) (option (lambda unit unit)) ] */ } } -- GitLab From 56ff04517cbf20d79e3101abc8e6f6e782a58630 Mon Sep 17 00:00:00 2001 From: lykimq Date: Thu, 10 Nov 2022 10:54:53 +0700 Subject: [PATCH 4/4] Test/Python: remove bad_annotation test --- tests_python/tests_014/test_contract.py | 33 ----------------------- tests_python/tests_015/test_contract.py | 33 ----------------------- tests_python/tests_alpha/test_contract.py | 33 ----------------------- 3 files changed, 99 deletions(-) diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index edd0037577ec..feefa2bf77d8 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1103,39 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -BAD_ANNOT_TEST = ''' -parameter bytes; -storage (option (lambda unit unit)); -code { CAR; UNPACK (lambda unit unit); NIL operation; PAIR} -''' - - -@pytest.mark.incremental -@pytest.mark.contract -class TestBadAnnotation: - def test_write_contract_bad_annot(self, tmpdir, session: dict): - name = 'bad_annot.tz' - contract = f'{tmpdir}/{name}' - script = BAD_ANNOT_TEST - with open(contract, 'w') as contract_file: - contract_file.write(script) - session[name] = contract - - def test_bad_annotation(self, client: Client, session: dict): - name = 'bad_annot.tz' - contract = session[name] - - # This was produced by running "octez-client hash data '{ UNIT - # ; PAIR ; CAR %faa }' of type 'lambda unit unit'" and - # replacing the two last bytes (that correspond to the two - # 'a's at the end of the annotation) by the 0xff byte which is - # not a valid UTF8-encoding of a string - parameter = '0x05020000000e034f03420416000000042566ffff' - - res = client.run_script(contract, 'None', parameter) - assert res.storage == 'None' - - @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 edd0037577ec..feefa2bf77d8 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1103,39 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -BAD_ANNOT_TEST = ''' -parameter bytes; -storage (option (lambda unit unit)); -code { CAR; UNPACK (lambda unit unit); NIL operation; PAIR} -''' - - -@pytest.mark.incremental -@pytest.mark.contract -class TestBadAnnotation: - def test_write_contract_bad_annot(self, tmpdir, session: dict): - name = 'bad_annot.tz' - contract = f'{tmpdir}/{name}' - script = BAD_ANNOT_TEST - with open(contract, 'w') as contract_file: - contract_file.write(script) - session[name] = contract - - def test_bad_annotation(self, client: Client, session: dict): - name = 'bad_annot.tz' - contract = session[name] - - # This was produced by running "octez-client hash data '{ UNIT - # ; PAIR ; CAR %faa }' of type 'lambda unit unit'" and - # replacing the two last bytes (that correspond to the two - # 'a's at the end of the annotation) by the 0xff byte which is - # not a valid UTF8-encoding of a string - parameter = '0x05020000000e034f03420416000000042566ffff' - - res = client.run_script(contract, 'None', parameter) - assert res.storage == 'None' - - @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 edd0037577ec..feefa2bf77d8 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1103,39 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -BAD_ANNOT_TEST = ''' -parameter bytes; -storage (option (lambda unit unit)); -code { CAR; UNPACK (lambda unit unit); NIL operation; PAIR} -''' - - -@pytest.mark.incremental -@pytest.mark.contract -class TestBadAnnotation: - def test_write_contract_bad_annot(self, tmpdir, session: dict): - name = 'bad_annot.tz' - contract = f'{tmpdir}/{name}' - script = BAD_ANNOT_TEST - with open(contract, 'w') as contract_file: - contract_file.write(script) - session[name] = contract - - def test_bad_annotation(self, client: Client, session: dict): - name = 'bad_annot.tz' - contract = session[name] - - # This was produced by running "octez-client hash data '{ UNIT - # ; PAIR ; CAR %faa }' of type 'lambda unit unit'" and - # replacing the two last bytes (that correspond to the two - # 'a's at the end of the annotation) by the 0xff byte which is - # not a valid UTF8-encoding of a string - parameter = '0x05020000000e034f03420416000000042566ffff' - - res = client.run_script(contract, 'None', parameter) - assert res.storage == 'None' - - @pytest.mark.slow @pytest.mark.contract @pytest.mark.regression -- GitLab