From 10f3cb15295e6430f24eda1a02c8dd4b20d2ae86 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 2 Dec 2022 14:49:21 +0100 Subject: [PATCH 1/2] Tezt/Client: add [call] --- tezt/lib_tezos/client.ml | 24 ++++++++++++++++++++++++ tezt/lib_tezos/client.mli | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 9c6ff43fc739..8ec078ac9f15 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -895,6 +895,30 @@ let transfer ?hooks ?log_output ?endpoint ?wait ?burn_cap ?fee ?gas_limit client |> Process.check ?expect_failure +let spawn_call ?hooks ?log_output ?endpoint ?(wait = "none") ?burn_cap + ?entrypoint ?arg ~destination ~source client = + spawn_command ?log_output ?endpoint ?hooks client + @@ ["--wait"; wait] + @ ["call"; destination; "from"; source] + @ optional_arg "burn-cap" Tez.to_string burn_cap + @ optional_arg "entrypoint" Fun.id entrypoint + @ optional_arg "arg" Fun.id arg + +let call ?hooks ?log_output ?endpoint ?wait ?burn_cap ?entrypoint ?arg + ~destination ~source client = + spawn_call + ?hooks + ?log_output + ?endpoint + ?wait + ?burn_cap + ?entrypoint + ?arg + ~destination + ~source + client + |> Process.check + let multiple_transfers ?log_output ?endpoint ?(wait = "none") ?burn_cap ?fee_cap ?gas_limit ?storage_limit ?counter ?(simulation = false) ?(force = false) ~giver ~json_batch client = diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 4c3a364e620a..40582a992cb9 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -692,6 +692,34 @@ val spawn_transfer : t -> Process.t +(** Run [octez-client call from ]. *) +val call : + ?hooks:Process.hooks -> + ?log_output:bool -> + ?endpoint:endpoint -> + ?wait:string -> + ?burn_cap:Tez.t -> + ?entrypoint:string -> + ?arg:string -> + destination:string -> + source:string -> + t -> + unit Lwt.t + +(** Same as [call], but do not wait for the process to exit. *) +val spawn_call : + ?hooks:Process.hooks -> + ?log_output:bool -> + ?endpoint:endpoint -> + ?wait:string -> + ?burn_cap:Tez.t -> + ?entrypoint:string -> + ?arg:string -> + destination:string -> + source:string -> + t -> + Process.t + (** Run [octez-client multiple transfers from giver using json_batch]. *) val multiple_transfers : ?log_output:bool -> -- GitLab From 57b87a60cc2592c4d616d11462ac5daadb5b8e81 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 2 Dec 2022 14:52:06 +0100 Subject: [PATCH 2/2] Tezt: migrate [test_contract.py::TestManager] --- tests_python/tests_014/test_contract.py | 254 --------------- tests_python/tests_015/test_contract.py | 254 --------------- tests_python/tests_alpha/test_contract.py | 254 --------------- tezt/tests/main.ml | 1 + tezt/tests/script_manager_contracts.ml | 363 ++++++++++++++++++++++ 5 files changed, 364 insertions(+), 762 deletions(-) delete mode 100644 tests_python/tests_014/test_contract.py delete mode 100644 tests_python/tests_015/test_contract.py delete mode 100644 tests_python/tests_alpha/test_contract.py create mode 100644 tezt/tests/script_manager_contracts.ml diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py deleted file mode 100644 index caa86ec516ee..000000000000 --- a/tests_python/tests_014/test_contract.py +++ /dev/null @@ -1,254 +0,0 @@ -import os -import pytest - -from client.client import Client -from tools import utils -from tools.constants import IDENTITIES -from tools.utils import originate -from .contract_paths import CONTRACT_PATH - - -@pytest.mark.contract -@pytest.mark.incremental -class TestManager: - def test_manager_origination(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'manager.tz') - pubkey = IDENTITIES['bootstrap2']['identity'] - originate(client, session, path, f'"{pubkey}"', 1000) - originate( - client, session, path, f'"{pubkey}"', 1000, contract_name="manager2" - ) - - def test_delegatable_origination(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'delegatable_target.tz' - ) - pubkey = IDENTITIES['bootstrap2']['identity'] - originate( - client, session, path, f'Pair "{pubkey}" (Pair "hello" 45)', 1000 - ) - - def test_target_with_entrypoints_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'big_map_entrypoints.tz' - ) - originate( - client, session, path, 'Pair {} {}', 1000, contract_name='target' - ) - - def test_target_without_entrypoints_origination( - self, client: Client, session - ): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_entrypoint_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_entrypoints', - ) - - def test_target_without_default_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_default_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_default', - ) - - def test_target_with_root_origination(self, client: Client, session): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'rooted_target.tz') - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='rooted_target', - ) - - def test_manager_set_delegate(self, client: Client): - client.set_delegate('manager', 'bootstrap2', []) - utils.bake(client, bake_for='bootstrap5') - bootstrap2_pkh = IDENTITIES['bootstrap2']['identity'] - client.set_delegate('delegatable_target', bootstrap2_pkh, []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap2']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - client.set_delegate('manager', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - client.set_delegate('delegatable_target', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap3']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - - def test_manager_withdraw_delegate(self, client: Client): - client.withdraw_delegate('manager', []) - utils.bake(client, bake_for='bootstrap5') - client.withdraw_delegate('delegatable_target', []) - utils.bake(client, bake_for='bootstrap5') - assert client.get_delegate('manager', []).delegate is None - assert client.get_delegate('delegatable_target', []).delegate is None - - def test_transfer_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.001 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'bootstrap2', - 'manager', - ['--gas-limit', f'{128 * 15450 + 108}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000382 - fee_mutez = utils.mutez_of_tez(fee) - assert balance + amount_mutez == new_balance - assert ( - balance_bootstrap - fee_mutez - amount_mutez - == new_balance_bootstrap - ) - - def test_simple_transfer_from_manager_to_implicit(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.1 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'bootstrap2', - ['--gas-limit', f'{128 * 26350 + 12}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000542 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert ( - balance_bootstrap + amount_mutez - fee_mutez - == new_balance_bootstrap - ) - - def test_transfer_from_manager_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_dest = client.get_mutez_balance('manager2') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'manager2', - ['--gas-limit', f'{128 * 44950 + 112}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_dest = client.get_mutez_balance('manager2') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000731 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert balance_dest + amount_mutez == new_balance_dest - assert balance_bootstrap - fee_mutez == new_balance_bootstrap - - def test_transfer_from_manager_to_default(self, client: Client): - client.transfer( - 10, 'manager', 'bootstrap2', ['--entrypoint', 'default'] - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer(10, 'manager', 'manager', ['--entrypoint', 'default']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_target(self, client: Client): - client.transfer(10, 'manager', 'target', ['--burn-cap', '0.356']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_entrypoint_with_args( - self, client: Client - ): - arg = 'Pair "hello" 42' - # using 'transfer' - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - # using 'call' - client.call( - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.call( - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_no_entrypoint_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_no_default_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_rooted_target_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer( - 0, - 'manager', - 'rooted_target', - ['--arg', arg, '--entrypoint', 'root'], - ) - utils.bake(client, bake_for='bootstrap5') - - client.call( - 'manager', 'rooted_target', ['--arg', arg, '--entrypoint', 'root'] - ) - utils.bake(client, bake_for='bootstrap5') diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py deleted file mode 100644 index caa86ec516ee..000000000000 --- a/tests_python/tests_015/test_contract.py +++ /dev/null @@ -1,254 +0,0 @@ -import os -import pytest - -from client.client import Client -from tools import utils -from tools.constants import IDENTITIES -from tools.utils import originate -from .contract_paths import CONTRACT_PATH - - -@pytest.mark.contract -@pytest.mark.incremental -class TestManager: - def test_manager_origination(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'manager.tz') - pubkey = IDENTITIES['bootstrap2']['identity'] - originate(client, session, path, f'"{pubkey}"', 1000) - originate( - client, session, path, f'"{pubkey}"', 1000, contract_name="manager2" - ) - - def test_delegatable_origination(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'delegatable_target.tz' - ) - pubkey = IDENTITIES['bootstrap2']['identity'] - originate( - client, session, path, f'Pair "{pubkey}" (Pair "hello" 45)', 1000 - ) - - def test_target_with_entrypoints_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'big_map_entrypoints.tz' - ) - originate( - client, session, path, 'Pair {} {}', 1000, contract_name='target' - ) - - def test_target_without_entrypoints_origination( - self, client: Client, session - ): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_entrypoint_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_entrypoints', - ) - - def test_target_without_default_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_default_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_default', - ) - - def test_target_with_root_origination(self, client: Client, session): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'rooted_target.tz') - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='rooted_target', - ) - - def test_manager_set_delegate(self, client: Client): - client.set_delegate('manager', 'bootstrap2', []) - utils.bake(client, bake_for='bootstrap5') - bootstrap2_pkh = IDENTITIES['bootstrap2']['identity'] - client.set_delegate('delegatable_target', bootstrap2_pkh, []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap2']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - client.set_delegate('manager', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - client.set_delegate('delegatable_target', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap3']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - - def test_manager_withdraw_delegate(self, client: Client): - client.withdraw_delegate('manager', []) - utils.bake(client, bake_for='bootstrap5') - client.withdraw_delegate('delegatable_target', []) - utils.bake(client, bake_for='bootstrap5') - assert client.get_delegate('manager', []).delegate is None - assert client.get_delegate('delegatable_target', []).delegate is None - - def test_transfer_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.001 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'bootstrap2', - 'manager', - ['--gas-limit', f'{128 * 15450 + 108}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000382 - fee_mutez = utils.mutez_of_tez(fee) - assert balance + amount_mutez == new_balance - assert ( - balance_bootstrap - fee_mutez - amount_mutez - == new_balance_bootstrap - ) - - def test_simple_transfer_from_manager_to_implicit(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.1 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'bootstrap2', - ['--gas-limit', f'{128 * 26350 + 12}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000542 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert ( - balance_bootstrap + amount_mutez - fee_mutez - == new_balance_bootstrap - ) - - def test_transfer_from_manager_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_dest = client.get_mutez_balance('manager2') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'manager2', - ['--gas-limit', f'{128 * 44950 + 112}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_dest = client.get_mutez_balance('manager2') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000731 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert balance_dest + amount_mutez == new_balance_dest - assert balance_bootstrap - fee_mutez == new_balance_bootstrap - - def test_transfer_from_manager_to_default(self, client: Client): - client.transfer( - 10, 'manager', 'bootstrap2', ['--entrypoint', 'default'] - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer(10, 'manager', 'manager', ['--entrypoint', 'default']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_target(self, client: Client): - client.transfer(10, 'manager', 'target', ['--burn-cap', '0.356']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_entrypoint_with_args( - self, client: Client - ): - arg = 'Pair "hello" 42' - # using 'transfer' - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - # using 'call' - client.call( - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.call( - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_no_entrypoint_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_no_default_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_rooted_target_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer( - 0, - 'manager', - 'rooted_target', - ['--arg', arg, '--entrypoint', 'root'], - ) - utils.bake(client, bake_for='bootstrap5') - - client.call( - 'manager', 'rooted_target', ['--arg', arg, '--entrypoint', 'root'] - ) - utils.bake(client, bake_for='bootstrap5') diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py deleted file mode 100644 index caa86ec516ee..000000000000 --- a/tests_python/tests_alpha/test_contract.py +++ /dev/null @@ -1,254 +0,0 @@ -import os -import pytest - -from client.client import Client -from tools import utils -from tools.constants import IDENTITIES -from tools.utils import originate -from .contract_paths import CONTRACT_PATH - - -@pytest.mark.contract -@pytest.mark.incremental -class TestManager: - def test_manager_origination(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'manager.tz') - pubkey = IDENTITIES['bootstrap2']['identity'] - originate(client, session, path, f'"{pubkey}"', 1000) - originate( - client, session, path, f'"{pubkey}"', 1000, contract_name="manager2" - ) - - def test_delegatable_origination(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'delegatable_target.tz' - ) - pubkey = IDENTITIES['bootstrap2']['identity'] - originate( - client, session, path, f'Pair "{pubkey}" (Pair "hello" 45)', 1000 - ) - - def test_target_with_entrypoints_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'big_map_entrypoints.tz' - ) - originate( - client, session, path, 'Pair {} {}', 1000, contract_name='target' - ) - - def test_target_without_entrypoints_origination( - self, client: Client, session - ): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_entrypoint_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_entrypoints', - ) - - def test_target_without_default_origination(self, client: Client, session): - path = os.path.join( - CONTRACT_PATH, 'entrypoints', 'no_default_target.tz' - ) - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='target_no_default', - ) - - def test_target_with_root_origination(self, client: Client, session): - path = os.path.join(CONTRACT_PATH, 'entrypoints', 'rooted_target.tz') - originate( - client, - session, - path, - 'Pair "hello" 42', - 1000, - contract_name='rooted_target', - ) - - def test_manager_set_delegate(self, client: Client): - client.set_delegate('manager', 'bootstrap2', []) - utils.bake(client, bake_for='bootstrap5') - bootstrap2_pkh = IDENTITIES['bootstrap2']['identity'] - client.set_delegate('delegatable_target', bootstrap2_pkh, []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap2']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - client.set_delegate('manager', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - client.set_delegate('delegatable_target', 'bootstrap3', []) - utils.bake(client, bake_for='bootstrap5') - delegate = IDENTITIES['bootstrap3']['identity'] - assert client.get_delegate('manager', []).delegate == delegate - assert ( - client.get_delegate('delegatable_target', []).delegate == delegate - ) - - def test_manager_withdraw_delegate(self, client: Client): - client.withdraw_delegate('manager', []) - utils.bake(client, bake_for='bootstrap5') - client.withdraw_delegate('delegatable_target', []) - utils.bake(client, bake_for='bootstrap5') - assert client.get_delegate('manager', []).delegate is None - assert client.get_delegate('delegatable_target', []).delegate is None - - def test_transfer_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.001 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'bootstrap2', - 'manager', - ['--gas-limit', f'{128 * 15450 + 108}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000382 - fee_mutez = utils.mutez_of_tez(fee) - assert balance + amount_mutez == new_balance - assert ( - balance_bootstrap - fee_mutez - amount_mutez - == new_balance_bootstrap - ) - - def test_simple_transfer_from_manager_to_implicit(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10.1 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'bootstrap2', - ['--gas-limit', f'{128 * 26350 + 12}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000542 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert ( - balance_bootstrap + amount_mutez - fee_mutez - == new_balance_bootstrap - ) - - def test_transfer_from_manager_to_manager(self, client: Client): - balance = client.get_mutez_balance('manager') - balance_dest = client.get_mutez_balance('manager2') - balance_bootstrap = client.get_mutez_balance('bootstrap2') - amount = 10 - amount_mutez = utils.mutez_of_tez(amount) - client.transfer( - amount, - 'manager', - 'manager2', - ['--gas-limit', f'{128 * 44950 + 112}'], - ) - utils.bake(client, bake_for='bootstrap5') - new_balance = client.get_mutez_balance('manager') - new_balance_dest = client.get_mutez_balance('manager2') - new_balance_bootstrap = client.get_mutez_balance('bootstrap2') - fee = 0.000731 - fee_mutez = utils.mutez_of_tez(fee) - assert balance - amount_mutez == new_balance - assert balance_dest + amount_mutez == new_balance_dest - assert balance_bootstrap - fee_mutez == new_balance_bootstrap - - def test_transfer_from_manager_to_default(self, client: Client): - client.transfer( - 10, 'manager', 'bootstrap2', ['--entrypoint', 'default'] - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer(10, 'manager', 'manager', ['--entrypoint', 'default']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_target(self, client: Client): - client.transfer(10, 'manager', 'target', ['--burn-cap', '0.356']) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_entrypoint_with_args( - self, client: Client - ): - arg = 'Pair "hello" 42' - # using 'transfer' - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.transfer( - 0, - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - # using 'call' - client.call( - 'manager', - 'target', - ['--entrypoint', 'add_left', '--arg', arg, '--burn-cap', '0.067'], - ) - utils.bake(client, bake_for='bootstrap5') - client.call( - 'manager', - 'target', - ['--entrypoint', 'mem_left', '--arg', '"hello"'], - ) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_no_entrypoint_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_entrypoints', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_no_default_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer(0, 'manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - client.call('manager', 'target_no_default', ['--arg', arg]) - utils.bake(client, bake_for='bootstrap5') - - def test_transfer_from_manager_to_rooted_target_with_args( - self, client: Client - ): - arg = 'Left Unit' - client.transfer( - 0, - 'manager', - 'rooted_target', - ['--arg', arg, '--entrypoint', 'root'], - ) - utils.bake(client, bake_for='bootstrap5') - - client.call( - 'manager', 'rooted_target', ['--arg', arg, '--entrypoint', 'root'] - ) - utils.bake(client, bake_for='bootstrap5') diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 156a4887ee13..dd008db616b8 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -159,6 +159,7 @@ let register_protocol_tests_that_use_supports_correctly () = Script_execution_ordering.register ~protocols ; Script_hash_regression.register ~protocols ; Script_hash_multiple.register ~protocols ; + Script_manager_contracts.register ~protocols ; Self_address_transfer.register ~protocols ; Script_conversion.register ~protocols ; Script_illtyped.register ~protocols ; diff --git a/tezt/tests/script_manager_contracts.ml b/tezt/tests/script_manager_contracts.ml new file mode 100644 index 000000000000..8f3eb6628507 --- /dev/null +++ b/tezt/tests/script_manager_contracts.ml @@ -0,0 +1,363 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* *) +(* 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: Manager contracts + Invocation: dune exec tezt/tests/main.exe -- --file script_manager_contracts.ml + Subject: Tests origination and calls to manager contracts. +*) + +let test_manager_contracts = + Protocol.register_test ~__FILE__ ~title:"Manager" ~tags:["manager"] + @@ fun protocol -> + let prefix = + sf + "tests_python/contracts_%s" + (match protocol with + | Protocol.Alpha -> "alpha" + | _ -> sf "%03d" @@ Protocol.number protocol) + in + let* client = Client.init_mockup ~protocol () in + let check_delegate ~__LOC__ src expected_delegate = + let* delegate = Client.get_delegate ~src client in + Check.( + (delegate = expected_delegate) + (option string) + ~__LOC__ + ~error_msg:"Expected delegate %R, got %L") ; + unit + in + let check_balance ~__LOC__ account expected_balance = + let* balance = Client.get_balance_for ~account client in + Check.( + (balance = expected_balance) + Tez.typ + ~__LOC__ + ~error_msg:"Expected %R, got %L") ; + unit + in + let bootstrap1 = Constant.bootstrap1.alias in + Log.info "Manager origination" ; + let path = + Michelson_script.(find ~prefix ["entrypoints"; "manager"] protocol |> path) + in + let pubkey = Constant.bootstrap2.public_key_hash in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"manager" + ~src:bootstrap1 + ~prg:path + ~init:("\"" ^ pubkey ^ "\"") + ~amount:(Tez.of_int 1000) + client + in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"manager2" + ~src:bootstrap1 + ~prg:path + ~init:("\"" ^ pubkey ^ "\"") + ~amount:(Tez.of_int 1000) + client + in + + Log.info "Delegatable origination" ; + let path = + Michelson_script.( + find ~prefix ["entrypoints"; "delegatable_target"] protocol |> path) + in + let pubkey = Constant.bootstrap2.public_key_hash in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"delegatable_target" + ~prg:path + ~src:bootstrap1 + ~init:(sf {|Pair %S (Pair "hello" 45)|} pubkey) + ~amount:(Tez.of_int 1000) + client + in + Log.info "Target with entrypoints origination" ; + let path = + Michelson_script.( + find ~prefix ["entrypoints"; "big_map_entrypoints"] protocol |> path) + in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"target" + ~prg:path + ~src:bootstrap1 + ~init:"Pair {} {}" + ~amount:(Tez.of_int 1000) + client + in + Log.info "Target without entrypoints origination" ; + let path = + Michelson_script.( + find ~prefix ["entrypoints"; "no_entrypoint_target"] protocol |> path) + in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"target_no_entrypoints" + ~src:bootstrap1 + ~prg:path + ~init:{|Pair "hello" 42|} + ~amount:(Tez.of_int 1000) + client + in + Log.info "Target without default origination" ; + let path = + Michelson_script.( + find ~prefix ["entrypoints"; "no_default_target"] protocol |> path) + in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"target_no_default" + ~src:bootstrap1 + ~prg:path + ~init:{|Pair "hello" 42|} + ~amount:(Tez.of_int 1000) + client + in + Log.info "Target with root origination" ; + let path = + Michelson_script.( + find ~prefix ["entrypoints"; "rooted_target"] protocol |> path) + in + let* _contract = + Client.originate_contract + ~burn_cap:Tez.one + ~alias:"rooted_target" + ~src:bootstrap1 + ~prg:path + ~init:{|Pair "hello" 42|} + ~amount:(Tez.of_int 1000) + client + in + Log.info "Manager set delegate" ; + let*! () = Client.set_delegate ~src:"manager" ~delegate:"bootstrap2" client in + let bootstrap2_pkh = Constant.bootstrap2.public_key_hash in + let*! () = + Client.set_delegate + ~src:"delegatable_target" + ~delegate:bootstrap2_pkh + client + in + let delegate = Constant.bootstrap2.public_key_hash in + let* () = check_delegate ~__LOC__ "manager" (Some delegate) in + let* () = check_delegate ~__LOC__ "delegatable_target" (Some delegate) in + let*! () = Client.set_delegate ~src:"manager" ~delegate:"bootstrap3" client in + let*! () = + Client.set_delegate ~src:"delegatable_target" ~delegate:"bootstrap3" client + in + let delegate = Constant.bootstrap3.public_key_hash in + let* () = check_delegate ~__LOC__ "manager" (Some delegate) in + let* () = check_delegate ~__LOC__ "delegatable_target" (Some delegate) in + Log.info "Manager withdraw delegate" ; + let* () = Client.withdraw_delegate ~src:"manager" client in + let* () = Client.withdraw_delegate ~src:"delegatable_target" client in + let* () = check_delegate ~__LOC__ "manager" None in + let* () = check_delegate ~__LOC__ "delegatable_target" None in + Log.info "Transfer to manager" ; + let* balance = Client.get_balance_for ~account:"manager" client in + let* balance_bootstrap = + Client.get_balance_for ~account:"bootstrap2" client + in + let amount = Tez.of_mutez_int 10_001_000 in + let* () = + Client.transfer + ~amount + ~giver:"bootstrap2" + ~receiver:"manager" + ~gas_limit:((128 * 15450) + 108) + client + in + let fee = Tez.of_mutez_int 0_000_475 in + let* () = check_balance ~__LOC__ "manager" Tez.(balance + amount) in + let* () = + check_balance ~__LOC__ "bootstrap2" Tez.(balance_bootstrap - fee - amount) + in + Log.info "Simple transfer from manager to implicit" ; + let* balance = Client.get_balance_for ~account:"manager" client in + let* balance_bootstrap = + Client.get_balance_for ~account:"bootstrap2" client + in + let amount = Tez.of_mutez_int 10_100_000 in + let* () = + Client.transfer + ~amount + ~giver:"manager" + ~receiver:"bootstrap2" + ~gas_limit:((128 * 26350) + 12) + client + in + let fee = Tez.of_mutez_int 0_000_635 in + let* () = check_balance ~__LOC__ "manager" Tez.(balance - amount) in + let* () = + check_balance ~__LOC__ "bootstrap2" Tez.(balance_bootstrap + amount - fee) + in + Log.info "Transfer from manager to manager" ; + let* balance = Client.get_balance_for ~account:"manager" client in + let* balance_dest = Client.get_balance_for ~account:"manager2" client in + let* balance_bootstrap = + Client.get_balance_for ~account:"bootstrap2" client + in + let amount = Tez.of_int 10 in + let* () = + Client.transfer + ~amount + ~giver:"manager" + ~receiver:"manager2" + ~gas_limit:((128 * 44950) + 112) + client + in + let fee = Tez.of_mutez_int 0_000_824 in + let* () = check_balance ~__LOC__ "manager" Tez.(balance - amount) in + let* () = check_balance ~__LOC__ "manager2" Tez.(balance_dest + amount) in + let* () = check_balance ~__LOC__ "bootstrap2" Tez.(balance_bootstrap - fee) in + Log.info "Transfer from manager to default" ; + let amount = Tez.of_int 10 in + let* () = + Client.transfer + ~amount + ~giver:"manager" + ~receiver:"bootstrap2" + ~entrypoint:"default" + client + in + let* () = + Client.transfer + ~amount + ~giver:"manager" + ~receiver:"manager" + ~entrypoint:"default" + client + in + Log.info "Transfer from manager to target" ; + let* () = + Client.transfer + ~amount + ~giver:"manager" + ~receiver:"target" + ~burn_cap:(Tez.of_mutez_int 0_356_000) + client + in + Log.info "Transfer from manager to entrypoint with args" ; + let arg = {|Pair "hello" 42|} in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"manager" + ~receiver:"target" + ~entrypoint:"add_left" + ~arg + ~burn_cap:(Tez.of_mutez_int 0_067_000) + client + in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"manager" + ~receiver:"target" + ~entrypoint:"mem_left" + ~arg:{|"hello"|} + client + in + let* () = + Client.call + ~source:"manager" + ~destination:"target" + ~entrypoint:"add_left" + ~arg + ~burn_cap:(Tez.of_int 0_067_000) + client + in + let* () = + Client.call + ~source:"manager" + ~destination:"target" + ~entrypoint:"mem_left" + ~arg:{|"hello"|} + ~burn_cap:(Tez.of_int 0_067_000) + client + in + Log.info "Transfer from manager no entrypoint with args" ; + let arg = "Left Unit" in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"manager" + ~receiver:"target_no_entrypoints" + ~arg + client + in + let* () = + Client.call + ~source:"manager" + ~destination:"target_no_entrypoints" + ~arg + client + in + Log.info "Transfer from manager to no default with args" ; + let arg = "Left Unit" in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"manager" + ~receiver:"target_no_default" + ~arg + client + in + let* () = + Client.call ~source:"manager" ~destination:"target_no_default" ~arg client + in + Log.info "Transfer from manager to rooted target with args" ; + let arg = "Left Unit" in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"manager" + ~receiver:"rooted_target" + ~arg + ~entrypoint:"root" + client + in + let* () = + Client.call + ~source:"manager" + ~destination:"rooted_target" + ~arg + ~entrypoint:"root" + client + in + unit + +let register ~protocols = test_manager_contracts protocols -- GitLab