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 0000000000000000000000000000000000000000..cec7bccd1adfc404dbb1fb18291af5bf0c5fef2b --- /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 0000000000000000000000000000000000000000..cec7bccd1adfc404dbb1fb18291af5bf0c5fef2b --- /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 0000000000000000000000000000000000000000..cec7bccd1adfc404dbb1fb18291af5bf0c5fef2b --- /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 } 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 b8bff943b82b54a3a93181535a414d8a328b420a..12208dda027fc379fcca495b819a33ed5d262cb4 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 0000000000000000000000000000000000000000..60237fed1dd098d333cfbfe9348dc606fe4dc40a --- /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_014/test_contract.py b/tests_python/tests_014/test_contract.py index edd0037577ecea5b1911cc73d38ddbc64636ac68..feefa2bf77d8fe48e1bcde71aa6a79f270df2d42 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/_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 2bd065498cfcce0e4b03e478244fdf3e7583a29b..f99adaf18db0be1f729d52bb509ea725acbf0782 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 0000000000000000000000000000000000000000..92e763a15719ef9a97d7954bea66f1ad91bc4cab --- /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_015/test_contract.py b/tests_python/tests_015/test_contract.py index edd0037577ecea5b1911cc73d38ddbc64636ac68..feefa2bf77d8fe48e1bcde71aa6a79f270df2d42 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/_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 9d31db447ee8ba94691742a6980a65860a9c2fb1..20ad6c7671bf24004296b103680a750732e2ad41 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 0000000000000000000000000000000000000000..a48ddfdce69789bcbcdce742600a771fe4010e84 --- /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)) ] */ } } diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index edd0037577ecea5b1911cc73d38ddbc64636ac68..feefa2bf77d8fe48e1bcde71aa6a79f270df2d42 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 diff --git a/tezt/tests/bad_annot.ml b/tezt/tests/bad_annot.ml new file mode 100644 index 0000000000000000000000000000000000000000..0e7f680c63b8ac5e407fb4d1534ac275868c4c35 --- /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 4307dd688474c9a275026b0ed678075075952de9..60a2dad1b47e91bef94f308e4b015515168a12d8 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 ;