From 6fc0797bb006d73bfbb3c444701ae2437362b30a Mon Sep 17 00:00:00 2001 From: lykimq Date: Tue, 8 Nov 2022 09:50:19 +0700 Subject: [PATCH 1/2] Tezt: add contract entrypoints tests --- tezt/lib_tezos/client.ml | 9 + tezt/lib_tezos/client.mli | 8 + tezt/tests/contract_entrypoints.ml | 328 +++++++++++++++++++++++++++++ tezt/tests/main.ml | 1 + 4 files changed, 346 insertions(+) create mode 100644 tezt/tests/contract_entrypoints.ml diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 78078f18f89c..c2078b6d2980 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -2314,6 +2314,15 @@ let contract_code ?unparsing_mode address client = @ optional_arg "unparsing-mode" normalize_mode_to_string unparsing_mode) |> Process.check_and_read_stdout +let spawn_contract_entrypoint_type ~entrypoint ~contract client = + spawn_command + client + ["get"; "contract"; "entrypoint"; "type"; "of"; entrypoint; "for"; contract] + +let contract_entrypoint_type ~entrypoint ~contract client = + spawn_contract_entrypoint_type ~entrypoint ~contract client + |> Process.check_and_read_stdout + let sign_bytes ~signer ~data client = let* output = spawn_command client ["sign"; "bytes"; data; "for"; signer] diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index b27e4c0d0672..2fbc99df077e 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -1742,6 +1742,14 @@ val contract_storage : val contract_code : ?unparsing_mode:normalize_mode -> string -> t -> string Lwt.t +(** Get contract entrypoint type for a contract. *) +val contract_entrypoint_type : + entrypoint:string -> contract:string -> t -> string Lwt.t + +(** Same as [contract_entrypoint_type], but do not wait for the process to exit. *) +val spawn_contract_entrypoint_type : + entrypoint:string -> contract:string -> t -> Process.t + (** Sign a string of bytes with secret key of the given account. *) val sign_bytes : signer:string -> data:string -> t -> string Lwt.t diff --git a/tezt/tests/contract_entrypoints.ml b/tezt/tests/contract_entrypoints.ml new file mode 100644 index 000000000000..18248acb9fbb --- /dev/null +++ b/tezt/tests/contract_entrypoints.ml @@ -0,0 +1,328 @@ +(*****************************************************************************) +(* *) +(* 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_entrypoints.ml + Subject: Tests for the contract entrypoints +*) + +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 + +let extract_new_contract client_output = + match client_output =~* rex "New contract ?(KT1\\w{33})" with + | None -> + Test.fail + "Cannot extract new contract from client_output: %s" + client_output + | Some c -> return c + +(* Originates a contract that when called, creates a contract with a + rootname annotation. Such annotations comes in two flavors, thus the + parameterization. Then calls the first contract and verifies the + existence and type of the root entrypoint of the create contract. *) +let test_create_contract_rootname_originate ~contract protocol = + let* client = Client.init_mockup ~protocol () in + let prg = contract_path protocol "opcodes" contract in + let* contract_rootname = + Client.originate_contract + ~alias:contract + ~amount:(Tez.of_int 1000) + ~src:Constant.bootstrap1.alias + ~prg + ~init:"None" + ~burn_cap:Tez.one + client + in + let process = + Client.spawn_transfer + ~burn_cap:(Tez.of_int 10) + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:contract_rootname + ~arg:"Unit" + client + in + let* client_output = Process.check_and_read_stdout process in + let* kt_1 = extract_new_contract client_output in + let* entrypoint_type = + Client.contract_entrypoint_type ~entrypoint:"root" ~contract:kt_1 client + in + let expected = "Entrypoint root: unit" in + let () = + Check.( + (String.trim entrypoint_type = String.trim expected) + string + ~__LOC__ + ~error_msg: + ("the entrypoint 'root' of the originated contract should exist" + ^ " with type unit")) + in + unit + +let register_create_contract_rootname protocols = + ["create_contract_rootname.tz"; "create_contract_rootname_alt.tz"] + |> List.iter @@ fun contract -> + Protocol.register_test + ~__FILE__ + ~title:(sf "test %s" contract) + ~tags:["client"; "michelson"] + (test_create_contract_rootname_originate ~contract) + protocols + +(* Test CONTRACT with/without entrypoint annotation on literal address + parameters with/without entrypoint annotation *) +let originate_simple_entrypoints client ~protocol = + let prg = contract_path protocol "entrypoints" "simple_entrypoints.tz" in + let* contract = + Client.originate_contract + ~alias:"simple_entrypoints" + ~amount:Tez.zero + ~src:"bootstrap5" + ~prg + ~init:"Unit" + ~burn_cap:Tez.one + client + in + Lwt.return (client, contract) + +let script contract_annotation contract_type = + sf + {| +parameter address; +storage (option address); +code { CAR; CONTRACT %s %s; + IF_SOME { ADDRESS; SOME } { NONE address; }; NIL operation; PAIR } +|} + contract_annotation + contract_type + +let test_simple_entrypoints client ~contract_annotation ~contract_type ~param + ~expected_storage = + let prg = script contract_annotation contract_type in + let* actual_storage = + Client.run_script client ~prg ~storage:"None" ~input:param + in + Check.( + (actual_storage = expected_storage) + ~__LOC__ + string + ~error_msg:"Expected results %R, got %L") ; + unit + +let test_simple_entrypoints_parametrize client ~contract = + (* tests passing adr to CONTRACT %A unit + where adr has an entrypoint %A of type unit, is allowed. *) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"unit" + ~param:(sf {|"%s"|} contract) + ~expected_storage:(sf {|(Some "%s%%A")|} contract) + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%B" + ~contract_type:"string" + ~param:(sf {|"%s"|} contract) + ~expected_storage:(sf {|(Some "%s%%B")|} contract) + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%C" + ~contract_type:"nat" + ~param:(sf {|"%s"|} contract) + ~expected_storage:(sf {|(Some "%s%%C")|} contract) + in + (* tests passing adr%A to CONTRACT %A unit: redundant specification + of entrypoint not allowed so CONTRACT returns None*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"unit" + ~param:(sf {|"%s%%A"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"unit" + ~param:(sf {|"%s%%B"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"unit" + ~param:(sf {|"%s%%D"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"unit" + ~param:(sf {|"%s%%A"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%B" + ~contract_type:"unit" + ~param:(sf {|"%s%%A"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%D" + ~contract_type:"unit" + ~param:(sf {|"%s%%A"|} contract) + ~expected_storage:"None" + in + (* tests passing adr%A to CONTRACT unit: + where adr has an entrypoint %A of type unit, is allowed.*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"unit" + ~param:(sf {|"%s%%A"|} contract) + ~expected_storage:(sf {|(Some "%s%%A")|} contract) + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"string" + ~param:(sf {|"%s%%B"|} contract) + ~expected_storage:(sf {|(Some "%s%%B")|} contract) + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"nat" + ~param:(sf {|"%s%%C"|} contract) + ~expected_storage:(sf {|(Some "%s%%C")|} contract) + in + (* tests passing adr%B to CONTRACT unit: + as entrypoint %B of simple_entrypoints.tz has type string, + CONTRACT will return None.*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"unit" + ~param:(sf {|"%s%%B"|} contract) + ~expected_storage:"None" + in + (* tests passing adr%D to CONTRACT unit: + as entrypoint %D does not exist in simple_entrypoints.tz, + CONTRACT will return None.*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"unit" + ~param:(sf {|"%s%%D"|} contract) + ~expected_storage:"None" + in + (* tests passing adr to CONTRACT unit: + as adr does not have type unit, CONTRACT returns None.*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"" + ~contract_type:"unit" + ~param:(sf {|"%s"|} contract) + ~expected_storage:"None" + in + (* entrypoint that does not exist*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%D" + ~contract_type:"unit" + ~param:(sf {|"%s"|} contract) + ~expected_storage:"None" + in + (* ill-typed entrypoints*) + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%A" + ~contract_type:"int" + ~param:(sf {|"%s"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%B" + ~contract_type:"unit" + ~param:(sf {|"%s"|} contract) + ~expected_storage:"None" + in + let* () = + test_simple_entrypoints + client + ~contract_annotation:"%C" + ~contract_type:"int" + ~param:(sf {|"%s"|} contract) + ~expected_storage:"None" + in + unit + +let register_simple_entrypoints protocols = + Protocol.register_test + ~__FILE__ + ~title:"simple entrypoints" + ~tags:["client"; "michelson"] + (fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* client, contract = originate_simple_entrypoints client ~protocol in + test_simple_entrypoints_parametrize client ~contract) + protocols + +let register ~protocols = + register_create_contract_rootname protocols ; + register_simple_entrypoints protocols diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 6ee17c22c801..4307dd688474 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -106,6 +106,7 @@ let register_protocol_tests_that_use_supports_correctly () = Client_config.register ~protocols ; Client_run_view.register ~protocols ; Comparable_datatype.register ~protocols ; + Contract_entrypoints.register ~protocols ; Contract_hash_fun.register ~protocols ; Contract_hash_with_origination.register ~protocols ; Contract_opcodes.register ~protocols ; -- GitLab From 7f699ace95b5a763316375b4bb885cb83aa3488f Mon Sep 17 00:00:00 2001 From: lykimq Date: Thu, 10 Nov 2022 09:02:47 +0700 Subject: [PATCH 2/2] Python/Test: remove contract entrypoints tests --- tests_python/tests_014/test_contract.py | 122 ---------------------- tests_python/tests_015/test_contract.py | 122 ---------------------- tests_python/tests_alpha/test_contract.py | 122 ---------------------- 3 files changed, 366 deletions(-) diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index 6c2664cbe32b..edd0037577ec 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1103,128 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -@pytest.mark.incremental -@pytest.mark.contract -class TestMiniScenarios: - """Test mini scenarios""" - - # Originates a contract that when called, creates a contract with a - # rootname annotation. Such annotations comes in two flavors, thus the - # parameterization. Then calls the first contract and verifies the - # existence and type of the root entrypoint of the create contract. - @pytest.mark.parametrize( - "contract", - [ - 'create_contract_rootname.tz', - 'create_contract_rootname_alt.tz', - ], - ) - def test_create_contract_rootname_originate( - self, client: Client, session: dict, contract - ): - path = os.path.join(CONTRACT_PATH, 'opcodes', contract) - origination_res = originate(client, session, path, 'None', 1000) - - transfer_result = client.transfer( - 0, - "bootstrap1", - origination_res.contract, - ['-arg', 'Unit', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - - entrypoint_type = client.get_contract_entrypoint_type( - 'root', kt_1 - ).entrypoint_type - - assert entrypoint_type == 'unit', ( - 'the entrypoint my_root of the originated contract should exist' - 'with type unit' - ) - - # Test CONTRACT with/without entrypoint annotation on literal address - # parameters with/without entrypoint annotation - def test_originate_simple_entrypoints(self, session: dict, client: Client): - """originates the contract simple_entrypoints.tz - with entrypoint %A of type unit used in - test_simple_entrypoints""" - - contract_target = os.path.join( - CONTRACT_PATH, 'entrypoints', 'simple_entrypoints.tz' - ) - originate(client, session, contract_target, 'Unit', 0) - utils.bake(client, bake_for='bootstrap5') - - @pytest.mark.parametrize( - 'contract_annotation, contract_type, param, expected_storage', - [ - # tests passing adr to CONTRACT %A unit - # where adr has an entrypoint %A of type unit, is allowed. - ('%A', 'unit', '"{adr}"', '(Some "{adr}%A")'), - ('%B', 'string', '"{adr}"', '(Some "{adr}%B")'), - ('%C', 'nat', '"{adr}"', '(Some "{adr}%C")'), - # tests passing adr%A to CONTRACT %A unit: redundant specification - # of entrypoint not allowed so CONTRACT returns None - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%A', 'unit', '"{adr}%B"', 'None'), - ('%A', 'unit', '"{adr}%D"', 'None'), - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%B', 'unit', '"{adr}%A"', 'None'), - ('%D', 'unit', '"{adr}%A"', 'None'), - # tests passing adr%A to CONTRACT unit: - # where adr has an entrypoint %A of type unit, is allowed. - ('', 'unit', '"{adr}%A"', '(Some "{adr}%A")'), - ('', 'string', '"{adr}%B"', '(Some "{adr}%B")'), - ('', 'nat', '"{adr}%C"', '(Some "{adr}%C")'), - # tests passing adr%B to CONTRACT unit: - # as entrypoint %B of simple_entrypoints.tz has type string, - # CONTRACT will return None. - ('', 'unit', '"{adr}%B"', 'None'), - # tests passing adr%D to CONTRACT unit: - # as entrypoint %D does not exist in simple_entrypoints.tz, - # CONTRACT will return None. - ('', 'unit', '"{adr}%D"', 'None'), - # tests passing adr to CONTRACT unit: - # as adr does not have type unit, CONTRACT returns None. - ('', 'unit', '"{adr}"', 'None'), - # entrypoint that does not exist - ('%D', 'unit', '"{adr}"', 'None'), - # ill-typed entrypoints - ('%A', 'int', '"{adr}"', 'None'), - ('%B', 'unit', '"{adr}"', 'None'), - ('%C', 'int', '"{adr}"', 'None'), - ], - ) - def test_simple_entrypoints( - self, - session, - client, - contract_annotation, - contract_type, - param, - expected_storage, - ): - contract = f'''parameter address; -storage (option address); -code {{ - CAR; - CONTRACT {contract_annotation} {contract_type}; - IF_SOME {{ ADDRESS; SOME }} {{ NONE address; }}; - NIL operation; - PAIR - }};''' - - param = param.format(adr=session['contract']) - expected_storage = expected_storage.format(adr=session['contract']) - run_script_res = client.run_script(contract, 'None', param, file=False) - assert run_script_res.storage == expected_storage - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index 6c2664cbe32b..edd0037577ec 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1103,128 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -@pytest.mark.incremental -@pytest.mark.contract -class TestMiniScenarios: - """Test mini scenarios""" - - # Originates a contract that when called, creates a contract with a - # rootname annotation. Such annotations comes in two flavors, thus the - # parameterization. Then calls the first contract and verifies the - # existence and type of the root entrypoint of the create contract. - @pytest.mark.parametrize( - "contract", - [ - 'create_contract_rootname.tz', - 'create_contract_rootname_alt.tz', - ], - ) - def test_create_contract_rootname_originate( - self, client: Client, session: dict, contract - ): - path = os.path.join(CONTRACT_PATH, 'opcodes', contract) - origination_res = originate(client, session, path, 'None', 1000) - - transfer_result = client.transfer( - 0, - "bootstrap1", - origination_res.contract, - ['-arg', 'Unit', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - - entrypoint_type = client.get_contract_entrypoint_type( - 'root', kt_1 - ).entrypoint_type - - assert entrypoint_type == 'unit', ( - 'the entrypoint my_root of the originated contract should exist' - 'with type unit' - ) - - # Test CONTRACT with/without entrypoint annotation on literal address - # parameters with/without entrypoint annotation - def test_originate_simple_entrypoints(self, session: dict, client: Client): - """originates the contract simple_entrypoints.tz - with entrypoint %A of type unit used in - test_simple_entrypoints""" - - contract_target = os.path.join( - CONTRACT_PATH, 'entrypoints', 'simple_entrypoints.tz' - ) - originate(client, session, contract_target, 'Unit', 0) - utils.bake(client, bake_for='bootstrap5') - - @pytest.mark.parametrize( - 'contract_annotation, contract_type, param, expected_storage', - [ - # tests passing adr to CONTRACT %A unit - # where adr has an entrypoint %A of type unit, is allowed. - ('%A', 'unit', '"{adr}"', '(Some "{adr}%A")'), - ('%B', 'string', '"{adr}"', '(Some "{adr}%B")'), - ('%C', 'nat', '"{adr}"', '(Some "{adr}%C")'), - # tests passing adr%A to CONTRACT %A unit: redundant specification - # of entrypoint not allowed so CONTRACT returns None - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%A', 'unit', '"{adr}%B"', 'None'), - ('%A', 'unit', '"{adr}%D"', 'None'), - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%B', 'unit', '"{adr}%A"', 'None'), - ('%D', 'unit', '"{adr}%A"', 'None'), - # tests passing adr%A to CONTRACT unit: - # where adr has an entrypoint %A of type unit, is allowed. - ('', 'unit', '"{adr}%A"', '(Some "{adr}%A")'), - ('', 'string', '"{adr}%B"', '(Some "{adr}%B")'), - ('', 'nat', '"{adr}%C"', '(Some "{adr}%C")'), - # tests passing adr%B to CONTRACT unit: - # as entrypoint %B of simple_entrypoints.tz has type string, - # CONTRACT will return None. - ('', 'unit', '"{adr}%B"', 'None'), - # tests passing adr%D to CONTRACT unit: - # as entrypoint %D does not exist in simple_entrypoints.tz, - # CONTRACT will return None. - ('', 'unit', '"{adr}%D"', 'None'), - # tests passing adr to CONTRACT unit: - # as adr does not have type unit, CONTRACT returns None. - ('', 'unit', '"{adr}"', 'None'), - # entrypoint that does not exist - ('%D', 'unit', '"{adr}"', 'None'), - # ill-typed entrypoints - ('%A', 'int', '"{adr}"', 'None'), - ('%B', 'unit', '"{adr}"', 'None'), - ('%C', 'int', '"{adr}"', 'None'), - ], - ) - def test_simple_entrypoints( - self, - session, - client, - contract_annotation, - contract_type, - param, - expected_storage, - ): - contract = f'''parameter address; -storage (option address); -code {{ - CAR; - CONTRACT {contract_annotation} {contract_type}; - IF_SOME {{ ADDRESS; SOME }} {{ NONE address; }}; - NIL operation; - PAIR - }};''' - - param = param.format(adr=session['contract']) - expected_storage = expected_storage.format(adr=session['contract']) - run_script_res = client.run_script(contract, 'None', param, file=False) - assert run_script_res.storage == expected_storage - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index 6c2664cbe32b..edd0037577ec 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1103,128 +1103,6 @@ class TestNonRegression: assert op1.storage_size == op2.storage_size -@pytest.mark.incremental -@pytest.mark.contract -class TestMiniScenarios: - """Test mini scenarios""" - - # Originates a contract that when called, creates a contract with a - # rootname annotation. Such annotations comes in two flavors, thus the - # parameterization. Then calls the first contract and verifies the - # existence and type of the root entrypoint of the create contract. - @pytest.mark.parametrize( - "contract", - [ - 'create_contract_rootname.tz', - 'create_contract_rootname_alt.tz', - ], - ) - def test_create_contract_rootname_originate( - self, client: Client, session: dict, contract - ): - path = os.path.join(CONTRACT_PATH, 'opcodes', contract) - origination_res = originate(client, session, path, 'None', 1000) - - transfer_result = client.transfer( - 0, - "bootstrap1", - origination_res.contract, - ['-arg', 'Unit', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - - entrypoint_type = client.get_contract_entrypoint_type( - 'root', kt_1 - ).entrypoint_type - - assert entrypoint_type == 'unit', ( - 'the entrypoint my_root of the originated contract should exist' - 'with type unit' - ) - - # Test CONTRACT with/without entrypoint annotation on literal address - # parameters with/without entrypoint annotation - def test_originate_simple_entrypoints(self, session: dict, client: Client): - """originates the contract simple_entrypoints.tz - with entrypoint %A of type unit used in - test_simple_entrypoints""" - - contract_target = os.path.join( - CONTRACT_PATH, 'entrypoints', 'simple_entrypoints.tz' - ) - originate(client, session, contract_target, 'Unit', 0) - utils.bake(client, bake_for='bootstrap5') - - @pytest.mark.parametrize( - 'contract_annotation, contract_type, param, expected_storage', - [ - # tests passing adr to CONTRACT %A unit - # where adr has an entrypoint %A of type unit, is allowed. - ('%A', 'unit', '"{adr}"', '(Some "{adr}%A")'), - ('%B', 'string', '"{adr}"', '(Some "{adr}%B")'), - ('%C', 'nat', '"{adr}"', '(Some "{adr}%C")'), - # tests passing adr%A to CONTRACT %A unit: redundant specification - # of entrypoint not allowed so CONTRACT returns None - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%A', 'unit', '"{adr}%B"', 'None'), - ('%A', 'unit', '"{adr}%D"', 'None'), - ('%A', 'unit', '"{adr}%A"', 'None'), - ('%B', 'unit', '"{adr}%A"', 'None'), - ('%D', 'unit', '"{adr}%A"', 'None'), - # tests passing adr%A to CONTRACT unit: - # where adr has an entrypoint %A of type unit, is allowed. - ('', 'unit', '"{adr}%A"', '(Some "{adr}%A")'), - ('', 'string', '"{adr}%B"', '(Some "{adr}%B")'), - ('', 'nat', '"{adr}%C"', '(Some "{adr}%C")'), - # tests passing adr%B to CONTRACT unit: - # as entrypoint %B of simple_entrypoints.tz has type string, - # CONTRACT will return None. - ('', 'unit', '"{adr}%B"', 'None'), - # tests passing adr%D to CONTRACT unit: - # as entrypoint %D does not exist in simple_entrypoints.tz, - # CONTRACT will return None. - ('', 'unit', '"{adr}%D"', 'None'), - # tests passing adr to CONTRACT unit: - # as adr does not have type unit, CONTRACT returns None. - ('', 'unit', '"{adr}"', 'None'), - # entrypoint that does not exist - ('%D', 'unit', '"{adr}"', 'None'), - # ill-typed entrypoints - ('%A', 'int', '"{adr}"', 'None'), - ('%B', 'unit', '"{adr}"', 'None'), - ('%C', 'int', '"{adr}"', 'None'), - ], - ) - def test_simple_entrypoints( - self, - session, - client, - contract_annotation, - contract_type, - param, - expected_storage, - ): - contract = f'''parameter address; -storage (option address); -code {{ - CAR; - CONTRACT {contract_annotation} {contract_type}; - IF_SOME {{ ADDRESS; SOME }} {{ NONE address; }}; - NIL operation; - PAIR - }};''' - - param = param.format(adr=session['contract']) - expected_storage = expected_storage.format(adr=session['contract']) - run_script_res = client.run_script(contract, 'None', param, file=False) - assert run_script_res.storage == expected_storage - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); -- GitLab