diff --git a/tests_python/contracts_015/mini_scenarios/tzip4_view.tz b/tests_python/contracts_015/mini_scenarios/tzip4_view.tz deleted file mode 100644 index aee5f1fa15f387acb404d31e62f7703f8cd1a857..0000000000000000000000000000000000000000 --- a/tests_python/contracts_015/mini_scenarios/tzip4_view.tz +++ /dev/null @@ -1,7 +0,0 @@ -parameter (or (pair %view_const unit (contract nat)) (pair %view_add (pair int int) (contract int))); -storage unit; -code { - CAR; - IF_LEFT {CDR; AMOUNT; PUSH nat 5; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR} - {UNPAIR; UNPAIR; ADD; AMOUNT; SWAP; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR}; - } diff --git a/tests_python/contracts_alpha/mini_scenarios/tzip4_view.tz b/tests_python/contracts_alpha/mini_scenarios/tzip4_view.tz deleted file mode 100644 index aee5f1fa15f387acb404d31e62f7703f8cd1a857..0000000000000000000000000000000000000000 --- a/tests_python/contracts_alpha/mini_scenarios/tzip4_view.tz +++ /dev/null @@ -1,7 +0,0 @@ -parameter (or (pair %view_const unit (contract nat)) (pair %view_add (pair int int) (contract int))); -storage unit; -code { - CAR; - IF_LEFT {CDR; AMOUNT; PUSH nat 5; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR} - {UNPAIR; UNPAIR; ADD; AMOUNT; SWAP; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; 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 22118ff04728f722c456ab7bcf0b4d2b4ebcb408..87e0ee3508d2af02793cb81c5e709bbd582a863c 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 @@ -93,7 +93,6 @@ expru9ASRmfbXX8Ajf5uDeiZDbNwonrCiS1e6UaDXUstKU3yuwQwdZ [CONTRACT_PATH]/mini_scen exprtXrMgaXhLsw6ioNNPThqPF1yDyLjqGdJeB6yMRKLUQZfkTD6jy [CONTRACT_PATH]/mini_scenarios/ticket_builder_non_fungible.tz expruryVEK55xjeHpeGgHjuLr9jtRS2D1gzAgYXpzGfripoX8qFhNK [CONTRACT_PATH]/mini_scenarios/ticket_wallet_fungible.tz expruoGtEJH3sXXm2ruNG6DGTFE3GM6fjAS6fzDZKtdaMnRzHvi3Xd [CONTRACT_PATH]/mini_scenarios/ticket_wallet_non_fungible.tz -exprtnBz8poqNTrK4rzTXZFKQx7HWpx4WidHB5wxcM2oTS8NcrkAUt [CONTRACT_PATH]/mini_scenarios/tzip4_view.tz exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scenarios/vote_for_delegate.tz expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz diff --git a/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out b/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out deleted file mode 100644 index f3a1024bd0bdc6ab2e005819e4df501976bebd5f..0000000000000000000000000000000000000000 --- a/tests_python/tests_014/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out +++ /dev/null @@ -1,55 +0,0 @@ -tests_014/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/tzip4_view.tz] - -Well typed -Gas remaining: 1039986.099 units remaining -{ parameter - (or (pair %view_const unit (contract nat)) - (pair %view_add (pair int int) (contract int))) ; - storage unit ; - code { CAR - /* [ or (pair unit (contract nat)) (pair (pair int int) (contract int)) ] */ ; - IF_LEFT - { CDR - /* [ contract nat ] */ ; - AMOUNT - /* [ mutez : contract nat ] */ ; - PUSH nat 5 - /* [ nat : mutez : contract nat ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } - { UNPAIR - /* [ pair int int : contract int ] */ ; - UNPAIR - /* [ int : int : contract int ] */ ; - ADD - /* [ int : contract int ] */ ; - AMOUNT - /* [ mutez : int : contract int ] */ ; - SWAP - /* [ int : mutez : contract int ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } } } diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index 305d62c0dad851946f5d3fb6b6e89e91d7961a16..6fe671bee9515b397f17eed9621725dbf9f0645a 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -2027,33 +2027,6 @@ class TestNormalize: client.normalize_type(typ) -@pytest.mark.contract -class TestTZIP4View: - """Tests for the "run tzip4 view" command.""" - - def test_run_view(self, client: Client, session: dict): - - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'tzip4_view.tz') - originate( - client, - session, - contract=path, - init_storage='Unit', - amount=1000, - contract_name='view_contract', - ) - utils.bake(client, bake_for='bootstrap5') - - const_view_res = client.run_view( - "view_const", "view_contract", "Unit", [] - ) - add_view_res = client.run_view( - "view_add", "view_contract", "Pair 1 3", [] - ) - - assert const_view_res.result == "5\n" and add_view_res.result == "4\n" - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: 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 4affd1a673e36480b13ac0648a1f72267973e8c3..c12ee596228f867ae782da8ce143f1a7f817aa2c 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 @@ -97,7 +97,6 @@ expruaFvFLsin2MWRuDkLRfe56pdPTUQ8RK9k1ks1rUTjBnwryPyPx [CONTRACT_PATH]/mini_scen expruMFhigCZpXrGaL5sMyjGw5k7CanAa7XRkHFemCoCwMfJFJjDuD [CONTRACT_PATH]/mini_scenarios/ticket_builder_non_fungible.tz exprthFU1n1xhXLi4D2G4andPJsLcem1g1UtKiKJjXkCfVHztC393b [CONTRACT_PATH]/mini_scenarios/ticket_wallet_fungible.tz expruoGtEJH3sXXm2ruNG6DGTFE3GM6fjAS6fzDZKtdaMnRzHvi3Xd [CONTRACT_PATH]/mini_scenarios/ticket_wallet_non_fungible.tz -exprtnBz8poqNTrK4rzTXZFKQx7HWpx4WidHB5wxcM2oTS8NcrkAUt [CONTRACT_PATH]/mini_scenarios/tzip4_view.tz exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scenarios/vote_for_delegate.tz expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz diff --git a/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out b/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out deleted file mode 100644 index 7ef12f2fbf92a1dcd6c79379c22340be2ea26d7b..0000000000000000000000000000000000000000 --- a/tests_python/tests_015/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out +++ /dev/null @@ -1,55 +0,0 @@ -tests_015/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/tzip4_view.tz] - -Well typed -Gas remaining: 1039986.099 units remaining -{ parameter - (or (pair %view_const unit (contract nat)) - (pair %view_add (pair int int) (contract int))) ; - storage unit ; - code { CAR - /* [ or (pair unit (contract nat)) (pair (pair int int) (contract int)) ] */ ; - IF_LEFT - { CDR - /* [ contract nat ] */ ; - AMOUNT - /* [ mutez : contract nat ] */ ; - PUSH nat 5 - /* [ nat : mutez : contract nat ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } - { UNPAIR - /* [ pair int int : contract int ] */ ; - UNPAIR - /* [ int : int : contract int ] */ ; - ADD - /* [ int : contract int ] */ ; - AMOUNT - /* [ mutez : int : contract int ] */ ; - SWAP - /* [ int : mutez : contract int ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } } } diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index 0c596355288e7ddb68a75660e59ac98b40288eee..2246374c103573a1e1c07d70f6f03d6af16c4e9d 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -2062,33 +2062,6 @@ class TestNormalize: client.normalize_type(typ) -@pytest.mark.contract -class TestTZIP4View: - """Tests for the "run tzip4 view" command.""" - - def test_run_view(self, client: Client, session: dict): - - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'tzip4_view.tz') - originate( - client, - session, - contract=path, - init_storage='Unit', - amount=1000, - contract_name='view_contract', - ) - utils.bake(client, bake_for='bootstrap5') - - const_view_res = client.run_view( - "view_const", "view_contract", "Unit", [] - ) - add_view_res = client.run_view( - "view_add", "view_contract", "Pair 1 3", [] - ) - - assert const_view_res.result == "5\n" and add_view_res.result == "4\n" - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: 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 8bc7efa485ed320f184160ed080f23d80765d450..e2e7e5dbfc27958e92ba50f551df4b3686cb85fd 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 @@ -95,7 +95,6 @@ expruaFvFLsin2MWRuDkLRfe56pdPTUQ8RK9k1ks1rUTjBnwryPyPx [CONTRACT_PATH]/mini_scen expruMFhigCZpXrGaL5sMyjGw5k7CanAa7XRkHFemCoCwMfJFJjDuD [CONTRACT_PATH]/mini_scenarios/ticket_builder_non_fungible.tz exprthFU1n1xhXLi4D2G4andPJsLcem1g1UtKiKJjXkCfVHztC393b [CONTRACT_PATH]/mini_scenarios/ticket_wallet_fungible.tz expruoGtEJH3sXXm2ruNG6DGTFE3GM6fjAS6fzDZKtdaMnRzHvi3Xd [CONTRACT_PATH]/mini_scenarios/ticket_wallet_non_fungible.tz -exprtnBz8poqNTrK4rzTXZFKQx7HWpx4WidHB5wxcM2oTS8NcrkAUt [CONTRACT_PATH]/mini_scenarios/tzip4_view.tz exprugya6ngixBfjyxV28ffnC8jmJPi4vbJdqD1aVUx82YLhzbH8Tn [CONTRACT_PATH]/mini_scenarios/vote_for_delegate.tz expruaKedvXmhg6wbV361DHykomz5dPqLi473KxBwJwyicEnKMhpb9 [CONTRACT_PATH]/mini_scenarios/weather_insurance.tz exprv9PvyjnsPjPCg5f13WtBiuD3o6idDAVWU6QfPtdWMjCLGRpwTh [CONTRACT_PATH]/mini_scenarios/xcat.tz diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out deleted file mode 100644 index 0d4f3112d8931a8bccc8f4dcc489dcf8a1ea3836..0000000000000000000000000000000000000000 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--tzip4_view.tz].out +++ /dev/null @@ -1,55 +0,0 @@ -tests_alpha/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/tzip4_view.tz] - -Well typed -Gas remaining: 1039986.099 units remaining -{ parameter - (or (pair %view_const unit (contract nat)) - (pair %view_add (pair int int) (contract int))) ; - storage unit ; - code { CAR - /* [ or (pair unit (contract nat)) (pair (pair int int) (contract int)) ] */ ; - IF_LEFT - { CDR - /* [ contract nat ] */ ; - AMOUNT - /* [ mutez : contract nat ] */ ; - PUSH nat 5 - /* [ nat : mutez : contract nat ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } - { UNPAIR - /* [ pair int int : contract int ] */ ; - UNPAIR - /* [ int : int : contract int ] */ ; - ADD - /* [ int : contract int ] */ ; - AMOUNT - /* [ mutez : int : contract int ] */ ; - SWAP - /* [ int : mutez : contract int ] */ ; - TRANSFER_TOKENS - /* [ operation ] */ ; - NIL operation - /* [ list operation : operation ] */ ; - SWAP - /* [ operation : list operation ] */ ; - CONS - /* [ list operation ] */ ; - UNIT - /* [ unit : list operation ] */ ; - SWAP - /* [ list operation : unit ] */ ; - PAIR - /* [ pair (list operation) unit ] */ } } } diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index 305d62c0dad851946f5d3fb6b6e89e91d7961a16..6fe671bee9515b397f17eed9621725dbf9f0645a 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -2027,33 +2027,6 @@ class TestNormalize: client.normalize_type(typ) -@pytest.mark.contract -class TestTZIP4View: - """Tests for the "run tzip4 view" command.""" - - def test_run_view(self, client: Client, session: dict): - - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'tzip4_view.tz') - originate( - client, - session, - contract=path, - init_storage='Unit', - amount=1000, - contract_name='view_contract', - ) - utils.bake(client, bake_for='bootstrap5') - - const_view_res = client.run_view( - "view_const", "view_contract", "Unit", [] - ) - add_view_res = client.run_view( - "view_add", "view_contract", "Pair 1 3", [] - ) - - assert const_view_res.result == "5\n" and add_view_res.result == "4\n" - - @pytest.mark.contract @pytest.mark.incremental class TestContractTypeChecking: diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index c635054abc9d014ff94c4e8eaae0255fc26f0bbf..814c3f0ff170e47a439cc8094add3096f06d10be 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -1447,6 +1447,37 @@ let typecheck_script ~script ?(details = false) ?(emacs = false) client |> Process.check_and_read_stdout +let spawn_run_tzip4_view ?hooks ?source ?payer ?gas ?unparsing_mode ~entrypoint + ~contract ?input ?(unlimited_gas = false) client = + let input_params = + match input with None -> [] | Some input -> ["with"; "input"; input] + in + spawn_command + ?hooks + client + (["run"; "tzip4"; "view"; entrypoint; "on"; "contract"; contract] + @ input_params + @ optional_arg "payer" Fun.id payer + @ optional_arg "source" Fun.id source + @ optional_arg "unparsing-mode" normalize_mode_to_string unparsing_mode + @ optional_arg "gas" Int.to_string gas + @ optional_switch "unlimited-gas" unlimited_gas) + +let run_tzip4_view ?hooks ?source ?payer ?gas ?unparsing_mode ~entrypoint + ~contract ?input ?unlimited_gas client = + spawn_run_tzip4_view + ?hooks + ?source + ?payer + ?gas + ?unparsing_mode + ~entrypoint + ~contract + ?input + ?unlimited_gas + client + |> Process.check_and_read_stdout + let spawn_run_view ?hooks ?source ?payer ?gas ?unparsing_mode ~view ~contract ?input ?(unlimited_gas = false) client = let input_params = diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index c4f77564780207a4f1c9f66c7fc444e8708dfee3..729493872c7b023e9acc15079535ceb3b09c43a1 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -1165,6 +1165,39 @@ val spawn_typecheck_script : t -> Process.t +(** Same as [run_tzip4_view] but does not wait for the process to exit. *) +val spawn_run_tzip4_view : + ?hooks:Process.hooks -> + ?source:string -> + ?payer:string -> + ?gas:int -> + ?unparsing_mode:normalize_mode -> + entrypoint:string -> + contract:string -> + ?input:string -> + ?unlimited_gas:bool -> + t -> + Process.t + +(** Run [tezos-client run tzip4 view .. on contract .. with input .. ] + + Returns the value returned by a view as a string. + + Fails if the view or the contract does not exist. If [input] is [None], + it runs [tezos-client run tzip4 view .. on contract ..]. *) +val run_tzip4_view : + ?hooks:Process.hooks -> + ?source:string -> + ?payer:string -> + ?gas:int -> + ?unparsing_mode:normalize_mode -> + entrypoint:string -> + contract:string -> + ?input:string -> + ?unlimited_gas:bool -> + t -> + string Lwt.t + (** Same as [run_view] but does not wait for the process to exit. *) val spawn_run_view : ?hooks:Process.hooks -> diff --git a/tests_python/contracts_014/mini_scenarios/tzip4_view.tz b/tezt/tests/contracts/proto_alpha/tzip4_view.tz similarity index 97% rename from tests_python/contracts_014/mini_scenarios/tzip4_view.tz rename to tezt/tests/contracts/proto_alpha/tzip4_view.tz index aee5f1fa15f387acb404d31e62f7703f8cd1a857..34f60e35025df86d2d50aa2e949edd622ba821b4 100644 --- a/tests_python/contracts_014/mini_scenarios/tzip4_view.tz +++ b/tezt/tests/contracts/proto_alpha/tzip4_view.tz @@ -4,4 +4,4 @@ code { CAR; IF_LEFT {CDR; AMOUNT; PUSH nat 5; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR} {UNPAIR; UNPAIR; ADD; AMOUNT; SWAP; TRANSFER_TOKENS; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR}; - } + } \ No newline at end of file diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 5db17812085a2e9133b7aaf01870ef8c6b65eb98..b65cc8481b23b54ae44214abf924e492c55b0ba8 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -137,8 +137,9 @@ let register_protocol_agnostic_tests () = Ticket_updates_in_receipt.register ~protocols:[Alpha] ; Timelock.register ~protocols ; Tickets.register ~protocols ; - Tx_rollup.register ~protocols:[Kathmandu; Lima; Alpha] ; - Tx_rollup_l2_node.register ~protocols:[Kathmandu; Lima; Alpha] ; + Tx_rollup.register ~protocols ; + Tx_rollup_l2_node.register ~protocols ; + Tzip4_view.register ~protocols ; Views.register [Alpha] ; Retro.register ~protocols diff --git a/tezt/tests/tzip4_view.ml b/tezt/tests/tzip4_view.ml new file mode 100644 index 0000000000000000000000000000000000000000..c120565d5533035c6ed09b0f355bcdf7a602e70d --- /dev/null +++ b/tezt/tests/tzip4_view.ml @@ -0,0 +1,88 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* 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 tzip4_view.ml + Subject: Tests for the "run tzip4 view" command +*) + +let init_with_contract ~protocol () = + let* client = Client.init_mockup ~protocol () in + let* contract = + Client.originate_contract + ~alias:"tzip4_view.tz" + ~amount:(Tez.of_int 1000) + ~src:Constant.bootstrap1.alias + ~prg:"file:./tezt/tests/contracts/proto_alpha/tzip4_view.tz" + ~init:"Unit" + ~burn_cap:Tez.one + client + in + Lwt.return (client, contract) + +let test_run_view_generic ?unlimited_gas ~protocol ~entrypoint ~input ~expected + () = + let* client, contract = init_with_contract ~protocol () in + let* view = + Client.run_tzip4_view ?unlimited_gas ~entrypoint ~contract ?input client + in + Check.( + (String.trim view = expected) + string + ~__LOC__ + ~error_msg:"Expected view result %R, got %L") ; + unit + +let test_run_view_const ~protocol () = + test_run_view_generic + ~protocol + ~entrypoint:"view_const" + ~input:(Some "Unit") + ~expected:"5" + () + +let test_run_view_add ~protocol () = + test_run_view_generic + ~protocol + ~entrypoint:"view_add" + ~input:(Some "Pair 1 3") + ~expected:"4" + () + +let register ~protocols = + List.iter + (fun (title, test_function) -> + Protocol.register_test + ~__FILE__ + ~title + ~tags:["client"; "michelson"; "tzip4_view"] + (fun protocol -> test_function ~protocol ()) + protocols) + [ + ("Run tzip4_view `tzip4_view_const`", test_run_view_const); + ("Run tzip4_view `tzip4_view_add`", test_run_view_add); + ]