diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index fadefc087f92a6ec79fe35fcc72e7dc4f96f9724..607934590b3dbbe3eb7ba3c746b74c9c044c11de 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1872,25 +1872,6 @@ class TestScriptHashRegression: ) -@pytest.mark.contract -class TestScriptHashOrigination: - def test_contract_hash_with_origination( - self, client: Client, session: dict - ): - script = ID_SCRIPT_LITERAL - originate( - client, - session, - contract=script, - init_storage='Unit', - amount=1000, - contract_name='dummy_contract', - ) - [(hash1, _)] = client.hash_script([script]) - hash2 = client.get_script_hash('dummy_contract') - assert hash1 == hash2 - - @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 fadefc087f92a6ec79fe35fcc72e7dc4f96f9724..607934590b3dbbe3eb7ba3c746b74c9c044c11de 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1872,25 +1872,6 @@ class TestScriptHashRegression: ) -@pytest.mark.contract -class TestScriptHashOrigination: - def test_contract_hash_with_origination( - self, client: Client, session: dict - ): - script = ID_SCRIPT_LITERAL - originate( - client, - session, - contract=script, - init_storage='Unit', - amount=1000, - contract_name='dummy_contract', - ) - [(hash1, _)] = client.hash_script([script]) - hash2 = client.get_script_hash('dummy_contract') - assert hash1 == hash2 - - @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 fadefc087f92a6ec79fe35fcc72e7dc4f96f9724..607934590b3dbbe3eb7ba3c746b74c9c044c11de 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1872,25 +1872,6 @@ class TestScriptHashRegression: ) -@pytest.mark.contract -class TestScriptHashOrigination: - def test_contract_hash_with_origination( - self, client: Client, session: dict - ): - script = ID_SCRIPT_LITERAL - originate( - client, - session, - contract=script, - init_storage='Unit', - amount=1000, - contract_name='dummy_contract', - ) - [(hash1, _)] = client.hash_script([script]) - hash2 = client.get_script_hash('dummy_contract') - assert hash1 == hash2 - - @pytest.mark.contract class TestScriptHashMultiple: """Test octez-client hash script with diffent number and type of diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index aed3c3a7f053869612be4f4f7272ed56d37ad3ed..331174539feadcaf9e2dfede742385c403fadb66 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -1423,6 +1423,16 @@ let spawn_hash_script ?hooks ~script client = let hash_script ?hooks ~script client = spawn_hash_script ?hooks ~script client |> Process.check_and_read_stdout +let spawn_get_contract_hash ?hooks ~contract client = + spawn_command + ?hooks + client + ["get"; "contract"; "script"; "hash"; "for"; contract] + +let get_contract_hash ?hooks ~contract client = + spawn_get_contract_hash ?hooks ~contract client + |> Process.check_and_read_stdout + let spawn_hash_data ?hooks ~data ~typ client = let cmd = ["hash"; "data"; data; "of"; "type"; typ] in spawn_command ?hooks client cmd diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index ae16f99f73ec65670d735be3ee2aaf6003df966f..2bffa6a64e65df6352edc730aa59851721605fb0 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -1165,6 +1165,14 @@ val hash_script : ?hooks:Process_hooks.t -> script:string -> t -> string Lwt.t val spawn_hash_script : ?hooks:Process_hooks.t -> script:string -> t -> Process.t +(** Run [octez-client get contract script hash for ..]*) +val get_contract_hash : + ?hooks:Process_hooks.t -> contract:string -> t -> string Lwt.t + +(** Same as [get_contract_hash], but do not wait for the process to exit. *) +val spawn_get_contract_hash : + ?hooks:Process_hooks.t -> contract:string -> t -> Process.t + (** Run [octez-client normalize data .. of type ...]*) val normalize_data : ?mode:normalize_mode -> diff --git a/tezt/tests/contract_hash_with_origination.ml b/tezt/tests/contract_hash_with_origination.ml new file mode 100644 index 0000000000000000000000000000000000000000..eb7597ece1f61570b31f8e6f3e9d5580d95937d1 --- /dev/null +++ b/tezt/tests/contract_hash_with_origination.ml @@ -0,0 +1,80 @@ +(*****************************************************************************) +(* *) +(* 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_hash_with_origination.ml + Subject: Tests that `get contract script hash for ` return the + same value as directly hashing the script. +*) + +let contract_path protocol contract = + sf + "tests_python/contracts_%s/opcodes/%s" + (match protocol with + | Protocol.Alpha -> "alpha" + | _ -> sf "%03d" @@ Protocol.number protocol) + contract + +let test_contract_hash_with_origination ~protocol () = + let* client = Client.init_mockup ~protocol () in + let prg = contract_path protocol "noop.tz" in + let script = read_file prg in + let* contract = + Client.originate_contract + ~alias:"noop" + ~amount:(Tez.of_int 1000) + ~src:Constant.bootstrap1.alias + ~prg + ~init:"Unit" + ~burn_cap:Tez.one + client + in + let* received_script_hash = Client.hash_script client ~script in + let returned_script_hash = String.trim received_script_hash in + let* received_contract_hash = Client.get_contract_hash client ~contract in + let returned_contract_hash = String.trim received_contract_hash in + Check.( + (returned_script_hash = returned_contract_hash) + string + ~__LOC__ + ~error_msg:"Expected contract hash %R, got %L") ; + unit + +let register ~protocols = + List.iter + (fun (title, test_function) -> + Protocol.register_test + ~__FILE__ + ~title + ~tags:["client"; "michelson"] + (fun protocol -> test_function ~protocol ()) + protocols) + [ + ( "Test `get contract hash with origination for`", + test_contract_hash_with_origination ); + ] diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 577624899e9cd143668fd37890fd076ec1bb72e3..d80b6ba8aad578632e2854f083a4710c59d0c57c 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 ; Contract_hash_fun.register ~protocols ; + Contract_hash_with_origination.register ~protocols ; Create_contract.register ~protocols ; Deposits_limit.register ~protocols ; Double_bake.register ~protocols ;