From 70e4a88100ae9051e35f04f14a644dfa028a379c Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:23:26 +0200 Subject: [PATCH 1/9] Tests/pytest: [test_transfer] in [test_mockup.py] is redundant It is already covered by [test_transfer] in [mockup.ml]. --- tests_python/tests_013/test_mockup.py | 21 --------------------- tests_python/tests_014/test_mockup.py | 21 --------------------- tests_python/tests_alpha/test_mockup.py | 21 --------------------- 3 files changed, 63 deletions(-) diff --git a/tests_python/tests_013/test_mockup.py b/tests_python/tests_013/test_mockup.py index db7ae705972c..71f70bbd75dd 100644 --- a/tests_python/tests_013/test_mockup.py +++ b/tests_python/tests_013/test_mockup.py @@ -84,27 +84,6 @@ def test_create_mockup_already_initialized(mockup_client: Client): assert res == CreateMockupResult.ALREADY_INITIALIZED -@pytest.mark.client -def test_transfer(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir -M mockup - transfer 1 from bootstrap1 to bootstrap2` - in a valid mockup environment. - The call must succeed and the balances must be updated correctly. - """ - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - - giver_balance_before = mockup_client.get_balance(giver) - receiver_balance_before = mockup_client.get_balance(receiver) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = mockup_client.get_balance(giver) - receiver_balance_after = mockup_client.get_balance(receiver) - - assert giver_balance_after < giver_balance_before - transferred - assert receiver_balance_after == receiver_balance_before + transferred - - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` @pytest.mark.parametrize( diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index d8b03e378c10..9b063a47c34f 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -84,27 +84,6 @@ def test_create_mockup_already_initialized(mockup_client: Client): assert res == CreateMockupResult.ALREADY_INITIALIZED -@pytest.mark.client -def test_transfer(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir -M mockup - transfer 1 from bootstrap1 to bootstrap2` - in a valid mockup environment. - The call must succeed and the balances must be updated correctly. - """ - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - - giver_balance_before = mockup_client.get_balance(giver) - receiver_balance_before = mockup_client.get_balance(receiver) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = mockup_client.get_balance(giver) - receiver_balance_after = mockup_client.get_balance(receiver) - - assert giver_balance_after < giver_balance_before - transferred - assert receiver_balance_after == receiver_balance_before + transferred - - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` @pytest.mark.parametrize( diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index aee36e0be962..a9488792e040 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -86,27 +86,6 @@ def test_create_mockup_already_initialized(mockup_client: Client): assert res == CreateMockupResult.ALREADY_INITIALIZED -@pytest.mark.client -def test_transfer(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir -M mockup - transfer 1 from bootstrap1 to bootstrap2` - in a valid mockup environment. - The call must succeed and the balances must be updated correctly. - """ - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - - giver_balance_before = mockup_client.get_balance(giver) - receiver_balance_before = mockup_client.get_balance(receiver) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = mockup_client.get_balance(giver) - receiver_balance_after = mockup_client.get_balance(receiver) - - assert giver_balance_after < giver_balance_before - transferred - assert receiver_balance_after == receiver_balance_before + transferred - - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` @pytest.mark.parametrize( -- GitLab From 213651f16010821ad3dc34294702e6b2bd9daf58 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:25:13 +0200 Subject: [PATCH 2/9] Tezt: rename [{test -> check}_balances_after_transfer] By convention, functions registering tests should be prefixed [test_] and this is not such a function. --- tezt/tests/mockup.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index 83105c949a55..7cde0eb65001 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -63,7 +63,7 @@ let test_rpc_header_shell = let transfer_data = (Constant.bootstrap1.alias, Tez.one, Constant.bootstrap2.alias) -let test_balances_after_transfer giver amount receiver = +let check_balances_after_transfer giver amount receiver = let giver_balance_before, giver_balance_after = giver in let receiver_balance_before, receiver_balance_after = receiver in if not Tez.(giver_balance_after < giver_balance_before - amount) then @@ -109,7 +109,7 @@ let test_transfer = let* receiver_balance_after = Client.get_balance_for ~account:receiver client in - test_balances_after_transfer + check_balances_after_transfer (giver_balance_before, giver_balance_after) amount (receiver_balance_before, receiver_balance_after) ; @@ -455,7 +455,7 @@ let test_migration_transfer ?migration_spec () = let* receiver_balance_after = Client.get_balance_for ~account:receiver client in - test_balances_after_transfer + check_balances_after_transfer (giver_balance_before, giver_balance_after) amount (receiver_balance_before, receiver_balance_after) ; -- GitLab From 8b117280a00032394ece34717b6c4db73333c5bc Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:25:58 +0200 Subject: [PATCH 3/9] Tezt/Client: add [{spawn,}_list_known_addresses] --- tezt/lib_tezos/client.ml | 21 +++++++++++++++++++++ tezt/lib_tezos/client.mli | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 0343dbb325c2..e635c5706766 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -721,6 +721,27 @@ let show_address ~alias client = in return @@ Account.parse_client_output ~alias ~client_output +let spawn_list_known_addresses client = + spawn_command client ["list"; "known"; "addresses"] + +let list_known_addresses client = + let* client_output = + spawn_list_known_addresses client |> Process.check_and_read_stdout + in + let addresses = + client_output |> String.trim |> String.split_on_char '\n' + |> List.map @@ fun line -> + match line =~** rex "(.*): ([^ ]*)" with + | Some (alias, pkh) -> (alias, pkh) + | None -> + Test.fail + "Cannot parse line %S from list of known addresses from \ + client_output: %s" + line + client_output + in + return addresses + let gen_and_show_keys ?alias client = let* alias = gen_keys ?alias client in show_address ~alias client diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 8d90dc59d9c3..ec41e53d1590 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -556,6 +556,14 @@ val show_address : alias:string -> t -> Account.key Lwt.t (which also implies that there is no output key to parse). *) val spawn_show_address : alias:string -> t -> Process.t +(** Run [tezos-client list known addresses] and parse the output into + a association list from aliases to public key hashes. *) +val list_known_addresses : t -> (string * string) list Lwt.t + +(** Same as [list_known_addresses] but do not wait for the process to + exit. *) +val spawn_list_known_addresses : t -> Process.t + (** Run [tezos-client gen keys] and return the key alias. The default value for [alias] is a fresh alias of the form [tezt_]. *) -- GitLab From 1fd1018ccb09e92de0a94f5283156f42982259be Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:26:22 +0200 Subject: [PATCH 4/9] Tezt: error message when no tests selected should mention --match --- tezt/lib_core/test.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tezt/lib_core/test.ml b/tezt/lib_core/test.ml index ddebbc706e6a..1dbe065c7822 100644 --- a/tezt/lib_core/test.ml +++ b/tezt/lib_core/test.ml @@ -862,6 +862,9 @@ let run_with_scheduler scheduler = @ List.map (fun x -> "--title " ^ Log.quote_shell x) Cli.options.tests_to_run + @ List.map + (fun r -> "--match " ^ Log.quote_shell (show_rex r)) + Cli.options.patterns_to_run @ Cli.options.tags_to_run @ List.map (sf "/%s") Cli.options.tags_not_to_run)) ; if Cli.options.list = None then -- GitLab From 099c28fd626301239fefaff791a179eb4bf119af Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:26:45 +0200 Subject: [PATCH 5/9] Tezt: [--match] should be caseless --- tezt/lib_core/cli.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tezt/lib_core/cli.ml b/tezt/lib_core/cli.ml index f84326c287c7..58ffb40fa92e 100644 --- a/tezt/lib_core/cli.ml +++ b/tezt/lib_core/cli.ml @@ -289,14 +289,14 @@ let init ?args () = Arg.String (fun pattern -> options.patterns_to_run <- - Base.rex pattern :: options.patterns_to_run), - " Only run tests matching PERL_REGEXP (see SELECTING \ - TESTS)." ); + Base.rex ~opts:[`Caseless] pattern :: options.patterns_to_run), + " Only run tests matching PERL_REGEXP (case \ + insensitive) (see SELECTING TESTS)." ); ( "-m", Arg.String (fun pattern -> options.patterns_to_run <- - Base.rex pattern :: options.patterns_to_run), + Base.rex ~opts:[`Caseless] pattern :: options.patterns_to_run), " Same as --match." ); ( "--title", Arg.String -- GitLab From 7025988da15cd7319ab53610088e50d64b772a6e Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:32:46 +0200 Subject: [PATCH 6/9] Tezt: migrate [list_mockup_protocols] of [test_mockup.py] --- tests_python/tests_013/test_mockup.py | 13 ------------- tests_python/tests_014/test_mockup.py | 13 ------------- tests_python/tests_alpha/test_mockup.py | 13 ------------- tezt/tests/mockup.ml | 17 ++++++++++++++++- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/tests_python/tests_013/test_mockup.py b/tests_python/tests_013/test_mockup.py index 71f70bbd75dd..b2318919dfb8 100644 --- a/tests_python/tests_013/test_mockup.py +++ b/tests_python/tests_013/test_mockup.py @@ -25,19 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_list_mockup_protocols(sandbox: Sandbox): - """Executes `tezos-client list mockup protocols` - The call must succeed and return a non empty list. - """ - try: - client = sandbox.create_client() - protocols = client.list_mockup_protocols().mockup_protocols - assert protocols - finally: - shutil.rmtree(client.base_dir) - - @pytest.mark.client def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index 9b063a47c34f..b7839934fb48 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -25,19 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_list_mockup_protocols(sandbox: Sandbox): - """Executes `tezos-client list mockup protocols` - The call must succeed and return a non empty list. - """ - try: - client = sandbox.create_client() - protocols = client.list_mockup_protocols().mockup_protocols - assert protocols - finally: - shutil.rmtree(client.base_dir) - - @pytest.mark.client def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index a9488792e040..d87632da17b5 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -27,19 +27,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_list_mockup_protocols(sandbox: Sandbox): - """Executes `tezos-client list mockup protocols` - The call must succeed and return a non empty list. - """ - try: - client = sandbox.create_client() - protocols = client.list_mockup_protocols().mockup_protocols - assert protocols - finally: - shutil.rmtree(client.base_dir) - - @pytest.mark.client def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index 7cde0eb65001..ab7b17a099cf 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -609,6 +609,19 @@ let test_storage_from_file = in unit) +(* Executes `tezos-client list mockup protocols`. The call must + succeed and return a non empty list. *) +let test_list_mockup_protocols () = + Test.register + ~__FILE__ + ~title:"(Mockup) List mockup protocols." + ~tags:["mockup"; "client"; "protocols"] + @@ fun () -> + let client = Client.create_with_mode Client.Mockup in + let* protocols = Client.list_protocols `Mockup client in + if protocols = [] then Test.fail "List of mockup protocols must be non-empty" ; + unit + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -633,4 +646,6 @@ let register_global_constants ~protocols = let register_constant_migration ~migrate_from ~migrate_to = test_migration_constants ~migrate_from ~migrate_to -let register_protocol_independent () = test_migration_transfer () +let register_protocol_independent () = + test_migration_transfer () ; + test_list_mockup_protocols () -- GitLab From 7a23c8cf502d9e4c869380e9a488f0b29aacc315 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:34:29 +0200 Subject: [PATCH 7/9] Tezt: migrate [create_mockup_dir_exists_nonempty] of [test_mockup.py] --- tests_python/tests_013/test_mockup.py | 17 ----------------- tests_python/tests_014/test_mockup.py | 17 ----------------- tests_python/tests_alpha/test_mockup.py | 17 ----------------- tezt/tests/mockup.ml | 22 +++++++++++++++++++++- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/tests_python/tests_013/test_mockup.py b/tests_python/tests_013/test_mockup.py index b2318919dfb8..383e6e75e046 100644 --- a/tests_python/tests_013/test_mockup.py +++ b/tests_python/tests_013/test_mockup.py @@ -25,23 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is a non empty directory which is NOT a mockup - directory. The call must fail. - """ - with tempfile.TemporaryDirectory(prefix='tezos-client.') as base_dir: - # Make the directory not empty - with open(os.path.join(base_dir, "whatever"), "w") as handle: - handle.write("") - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - assert res == CreateMockupResult.DIR_NOT_EMPTY - - @pytest.mark.client def test_retrieve_addresses(mockup_client: Client): """Retrieves known addresses of a fresh mockup. diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index b7839934fb48..9d96152a1b98 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -25,23 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is a non empty directory which is NOT a mockup - directory. The call must fail. - """ - with tempfile.TemporaryDirectory(prefix='tezos-client.') as base_dir: - # Make the directory not empty - with open(os.path.join(base_dir, "whatever"), "w") as handle: - handle.write("") - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - assert res == CreateMockupResult.DIR_NOT_EMPTY - - @pytest.mark.client def test_retrieve_addresses(mockup_client: Client): """Retrieves known addresses of a fresh mockup. diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index d87632da17b5..d1153027afb5 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -27,23 +27,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_dir_exists_nonempty(sandbox: Sandbox): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is a non empty directory which is NOT a mockup - directory. The call must fail. - """ - with tempfile.TemporaryDirectory(prefix='tezos-client.') as base_dir: - # Make the directory not empty - with open(os.path.join(base_dir, "whatever"), "w") as handle: - handle.write("") - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - assert res == CreateMockupResult.DIR_NOT_EMPTY - - @pytest.mark.client def test_retrieve_addresses(mockup_client: Client): """Retrieves known addresses of a fresh mockup. diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index ab7b17a099cf..f866c4c969b2 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -622,6 +622,25 @@ let test_list_mockup_protocols () = if protocols = [] then Test.fail "List of mockup protocols must be non-empty" ; unit +(* Executes [tezos-client --base-dir /tmp/mdir create mockup] when + [/tmp/mdir] is a non empty directory which is NOT a mockup + directory. The call must fail. *) +let test_create_mockup_dir_exists_nonempty = + Protocol.register_test + ~__FILE__ + ~title:"(Mockup) Create mockup in existing base dir" + ~tags:["mockup"; "client"; "base_dir"] + @@ fun protocol -> + let base_dir = Temp.dir "mockup_dir" in + Base.write_file ~contents:"" (base_dir ^ "/" ^ "whatever") ; + let client = Client.create_with_mode ~base_dir Client.Mockup in + let* () = + Client.spawn_create_mockup client ~protocol + |> Process.check_error + ~msg:(rex "is not empty, please specify a fresh base directory") + in + unit + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -633,7 +652,8 @@ let register ~protocols = test_rpc_header_shell protocols ; test_origination_from_unrevealed_fees protocols ; test_multiple_transfers protocols ; - test_storage_from_file protocols + test_storage_from_file protocols ; + test_create_mockup_dir_exists_nonempty protocols let register_global_constants ~protocols = test_register_global_constant_success protocols ; -- GitLab From 9e02cc20d99f28f378b0710e0f3c16add47613eb Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:35:25 +0200 Subject: [PATCH 8/9] Tezt: migrate [retrieve_addresses] of [test_mockup.py] --- tests_python/tests_013/test_mockup.py | 15 --------------- tests_python/tests_014/test_mockup.py | 15 --------------- tests_python/tests_alpha/test_mockup.py | 16 ---------------- tezt/tests/mockup.ml | 23 ++++++++++++++++++++++- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/tests_python/tests_013/test_mockup.py b/tests_python/tests_013/test_mockup.py index 383e6e75e046..947e92657eb5 100644 --- a/tests_python/tests_013/test_mockup.py +++ b/tests_python/tests_013/test_mockup.py @@ -25,21 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_retrieve_addresses(mockup_client: Client): - """Retrieves known addresses of a fresh mockup. - The call must succeed. - """ - addresses = mockup_client.get_known_addresses().wallet - assert addresses == { - 'bootstrap1': 'tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx', - 'bootstrap2': 'tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN', - 'bootstrap3': 'tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU', - 'bootstrap4': 'tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv', - 'bootstrap5': 'tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv', - } - - @pytest.mark.client def test_create_mockup_already_initialized(mockup_client: Client): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index 9d96152a1b98..4a284f318b09 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -25,21 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_retrieve_addresses(mockup_client: Client): - """Retrieves known addresses of a fresh mockup. - The call must succeed. - """ - addresses = mockup_client.get_known_addresses().wallet - assert addresses == { - 'bootstrap1': 'tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx', - 'bootstrap2': 'tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN', - 'bootstrap3': 'tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU', - 'bootstrap4': 'tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv', - 'bootstrap5': 'tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv', - } - - @pytest.mark.client def test_create_mockup_already_initialized(mockup_client: Client): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index d1153027afb5..9b7494d1650e 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -26,22 +26,6 @@ from . import protocol _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" - -@pytest.mark.client -def test_retrieve_addresses(mockup_client: Client): - """Retrieves known addresses of a fresh mockup. - The call must succeed. - """ - addresses = mockup_client.get_known_addresses().wallet - assert addresses == { - 'bootstrap1': 'tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx', - 'bootstrap2': 'tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN', - 'bootstrap3': 'tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU', - 'bootstrap4': 'tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv', - 'bootstrap5': 'tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv', - } - - @pytest.mark.client def test_create_mockup_already_initialized(mockup_client: Client): """Executes `tezos-client --base-dir /tmp/mdir create mockup` diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index f866c4c969b2..dbd00f6abb7d 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -641,6 +641,26 @@ let test_create_mockup_dir_exists_nonempty = in unit +let test_retrieve_addresses = + Protocol.register_test + ~__FILE__ + ~title:"(Mockup) Retrieve addresses" + ~tags:["mockup"; "client"; "wallet"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* addresses = Client.list_known_addresses client in + let expected_addresses = + Account.Bootstrap.keys |> Array.to_list |> List.rev + |> List.map @@ fun Account.{alias; public_key_hash; _} -> + (alias, public_key_hash) + in + Check.( + (addresses = expected_addresses) + ~__LOC__ + (list (tuple2 string string)) + ~error_msg:"Expected addresses %R, got %L") ; + unit + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -653,7 +673,8 @@ let register ~protocols = test_origination_from_unrevealed_fees protocols ; test_multiple_transfers protocols ; test_storage_from_file protocols ; - test_create_mockup_dir_exists_nonempty protocols + test_create_mockup_dir_exists_nonempty protocols ; + test_retrieve_addresses protocols let register_global_constants ~protocols = test_register_global_constant_success protocols ; -- GitLab From e13a74a46a82166e3ed037e672c3cf66275b0a16 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Fri, 23 Sep 2022 15:36:02 +0200 Subject: [PATCH 9/9] Tezt: migrate [create_mockup_already_initialized] of [test_mockup.py] --- tests_python/tests_013/test_mockup.py | 14 -------------- tests_python/tests_014/test_mockup.py | 14 -------------- tests_python/tests_alpha/test_mockup.py | 13 ------------- tezt/tests/mockup.ml | 19 ++++++++++++++++++- 4 files changed, 18 insertions(+), 42 deletions(-) diff --git a/tests_python/tests_013/test_mockup.py b/tests_python/tests_013/test_mockup.py index 947e92657eb5..61f10925244d 100644 --- a/tests_python/tests_013/test_mockup.py +++ b/tests_python/tests_013/test_mockup.py @@ -25,20 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_already_initialized(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is not fresh. - The call must fail. - """ - # mockup was created already by fixture, try to create it second time: - res = mockup_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - # it should fail: - assert res == CreateMockupResult.ALREADY_INITIALIZED - - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` @pytest.mark.parametrize( diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index 4a284f318b09..1000e5fd48cf 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -25,20 +25,6 @@ _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_already_initialized(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is not fresh. - The call must fail. - """ - # mockup was created already by fixture, try to create it second time: - res = mockup_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - # it should fail: - assert res == CreateMockupResult.ALREADY_INITIALIZED - - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` @pytest.mark.parametrize( diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index 9b7494d1650e..0c4c4ff739a3 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -26,19 +26,6 @@ from . import protocol _BA_FLAG = "bootstrap-accounts" _PC_FLAG = "protocol-constants" -@pytest.mark.client -def test_create_mockup_already_initialized(mockup_client: Client): - """Executes `tezos-client --base-dir /tmp/mdir create mockup` - when /tmp/mdir is not fresh. - The call must fail. - """ - # mockup was created already by fixture, try to create it second time: - res = mockup_client.create_mockup( - protocol=protocol.HASH, check=False - ).create_mockup_result - # it should fail: - assert res == CreateMockupResult.ALREADY_INITIALIZED - # It's impossible to guess values of chain_id, these ones have been # obtained by looking at the output of `compute chain id from seed` diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index dbd00f6abb7d..32d7ee63a216 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -661,6 +661,22 @@ let test_retrieve_addresses = ~error_msg:"Expected addresses %R, got %L") ; unit +(* Executes [tezos-client --base-dir /tmp/mdir create mockup] when + [/tmp/mdir] is not fresh. The call must fail. *) +let test_create_mockup_already_initialized = + Protocol.register_test + ~__FILE__ + ~title:"(Mockup) Create mockup when already initialized." + ~tags:["mockup"; "client"; "base_dir"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let* () = + Client.spawn_create_mockup client ~protocol + |> Process.check_error + ~msg:(rex "is already initialized as a mockup directory") + in + unit + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -674,7 +690,8 @@ let register ~protocols = test_multiple_transfers protocols ; test_storage_from_file protocols ; test_create_mockup_dir_exists_nonempty protocols ; - test_retrieve_addresses protocols + test_retrieve_addresses protocols ; + test_create_mockup_already_initialized protocols let register_global_constants ~protocols = test_register_global_constant_success protocols ; -- GitLab