From 32ef272659128967e46e9c271650f918a2090f1b Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Tue, 27 Sep 2022 11:25:48 +0200 Subject: [PATCH 1/3] Tezt/RPC: return [Tez.t] for select RPCs --- tezt/lib_tezos/RPC.ml | 26 +++++++++++++++----------- tezt/lib_tezos/RPC.mli | 18 +++++++++--------- tezt/tests/client_commands.ml | 7 ++----- tezt/tests/manager_operations.ml | 24 ++++++++++++------------ tezt/tests/prevalidator.ml | 6 +++--- tezt/tests/sapling.ml | 4 ++-- tezt/tests/sc_rollup.ml | 14 +++++++------- tezt/tests/tx_rollup.ml | 7 +++---- 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index d84d156fd127..848cffb38071 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -39,6 +39,10 @@ end let make ?data ?query_string = make ?data ?query_string ~get_host:Node.rpc_host ~get_port:Node.rpc_port +module Decode = struct + let mutez json = json |> JSON.as_int |> Tez.of_mutez_int +end + let get_config = make GET ["config"] Fun.id let get_network_connections = @@ -609,7 +613,7 @@ let get_chain_block_context_contract_balance ?(chain = "main") ?(block = "head") make GET ["chains"; chain; "blocks"; block; "context"; "contracts"; id; "balance"] - Fun.id + Decode.mutez let get_chain_block_context_contract_frozen_bonds ?(chain = "main") ?(block = "head") ~id () = @@ -625,7 +629,7 @@ let get_chain_block_context_contract_frozen_bonds ?(chain = "main") id; "frozen_bonds"; ] - Fun.id + Decode.mutez let get_chain_block_context_contract_balance_and_frozen_bonds ?(chain = "main") ?(block = "head") ~id () = @@ -641,7 +645,7 @@ let get_chain_block_context_contract_balance_and_frozen_bonds ?(chain = "main") id; "balance_and_frozen_bonds"; ] - Fun.id + Decode.mutez let post_chain_block_context_contract_big_map_get ?(chain = "main") ?(block = "head") ~id ~data () = @@ -810,7 +814,7 @@ let get_chain_block_context_delegate_current_frozen_deposits ?(chain = "main") pkh; "current_frozen_deposits"; ] - Fun.id + Decode.mutez let get_chain_block_context_delegate_deactivated ?(chain = "main") ?(block = "head") pkh = @@ -842,7 +846,7 @@ let get_chain_block_context_delegate_delegated_balance ?(chain = "main") pkh; "delegated_balance"; ] - Fun.id + Decode.mutez let get_chain_block_context_delegate_delegated_contracts ?(chain = "main") ?(block = "head") pkh = @@ -874,7 +878,7 @@ let get_chain_block_context_delegate_frozen_deposits ?(chain = "main") pkh; "frozen_deposits"; ] - JSON.(fun json -> json |> as_int |> Tez.of_mutez_int) + Decode.mutez let get_chain_block_context_delegate_frozen_deposits_limit ?(chain = "main") ?(block = "head") pkh = @@ -890,7 +894,7 @@ let get_chain_block_context_delegate_frozen_deposits_limit ?(chain = "main") pkh; "frozen_deposits_limit"; ] - Fun.id + (fun json -> json |> JSON.as_opt |> Option.map Decode.mutez) let get_chain_block_context_delegate_full_balance ?(chain = "main") ?(block = "head") pkh = @@ -906,7 +910,7 @@ let get_chain_block_context_delegate_full_balance ?(chain = "main") pkh; "full_balance"; ] - Fun.id + Decode.mutez let get_chain_block_context_delegate_grace_period ?(chain = "main") ?(block = "head") pkh = @@ -954,7 +958,7 @@ let get_chain_block_context_delegate_frozen_balance ?(chain = "main") pkh; "frozen_balance"; ] - JSON.(fun json -> json |> as_int |> Tez.of_mutez_int) + Decode.mutez let get_chain_block_context_delegate_frozen_balance_by_cycle ?(chain = "main") ?(block = "head") pkh = @@ -986,14 +990,14 @@ let get_chain_block_context_delegate_staking_balance ?(chain = "main") pkh; "staking_balance"; ] - Fun.id + Decode.mutez let get_chain_block_context_delegate_balance ?(chain = "main") ?(block = "head") pkh = make GET ["chains"; chain; "blocks"; block; "context"; "delegates"; pkh; "balance"] - Fun.id + Decode.mutez let get_chain_block_context_delegate_voting_info ?(chain = "main") ?(block = "head") pkh = diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 5c64d373ea1c..7a75e5a93b08 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -649,7 +649,7 @@ val get_chain_block_context_contract : [block] defaults to ["head"]. *) val get_chain_block_context_contract_balance : - ?chain:string -> ?block:string -> id:string -> unit -> JSON.t t + ?chain:string -> ?block:string -> id:string -> unit -> Tez.t t (** RPC [GET /chains//blocks//context/contracts//frozen_bonds] @@ -657,7 +657,7 @@ val get_chain_block_context_contract_balance : [block] defaults to ["head"]. *) val get_chain_block_context_contract_frozen_bonds : - ?chain:string -> ?block:string -> id:string -> unit -> JSON.t t + ?chain:string -> ?block:string -> id:string -> unit -> Tez.t t (** RPC [GET /chains//blocks//context/contracts//balance_and_frozen_bonds] @@ -665,7 +665,7 @@ val get_chain_block_context_contract_frozen_bonds : [block] defaults to ["head"]. *) val get_chain_block_context_contract_balance_and_frozen_bonds : - ?chain:string -> ?block:string -> id:string -> unit -> JSON.t t + ?chain:string -> ?block:string -> id:string -> unit -> Tez.t t (** RPC [POST /chains//blocks//context/contracts//big_map_get] @@ -775,7 +775,7 @@ val get_chain_block_context_delegate : [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_current_frozen_deposits : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t t (** RPC: [GET /chains//blocks//context/delegates//deactivated] @@ -803,7 +803,7 @@ val get_chain_block_context_delegate_frozen_balance_by_cycle : [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_delegated_balance : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t t (** RPC: [GET /chains//blocks//context/delegates//delegated_contracts] @@ -824,14 +824,14 @@ val get_chain_block_context_delegate_frozen_deposits : [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_frozen_deposits_limit : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t option t (** RPC: [GET /chains//blocks//context/delegates//full_balance] [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_full_balance : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t t (** RPC: [GET /chains//blocks//context/delegates//grace_period] @@ -852,14 +852,14 @@ val get_chain_block_context_delegate_participation : [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_balance : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t t (** RPC: [GET /chains//blocks//context/delegates//staking_balance] [chain] defaults to ["main"]. [block] defaults to ["head"]. *) val get_chain_block_context_delegate_staking_balance : - ?chain:string -> ?block:string -> string -> JSON.t t + ?chain:string -> ?block:string -> string -> Tez.t t (** RPC: [GET /chains//blocks//context/delegates//voting_info] diff --git a/tezt/tests/client_commands.ml b/tezt/tests/client_commands.ml index 7d734d17d68d..42b2e07fd297 100644 --- a/tezt/tests/client_commands.ml +++ b/tezt/tests/client_commands.ml @@ -179,11 +179,8 @@ end module Transfer = struct let get_balance pkh client = - let* json = - RPC.Client.call client - @@ RPC.get_chain_block_context_contract_balance ~id:pkh () - in - return (Tez.of_mutez_int (JSON.as_int json)) + RPC.Client.call client + @@ RPC.get_chain_block_context_contract_balance ~id:pkh () let alias_pkh_destination = Protocol.register_test diff --git a/tezt/tests/manager_operations.ml b/tezt/tests/manager_operations.ml index 4aa5566aecad..653f37be899e 100644 --- a/tezt/tests/manager_operations.ml +++ b/tezt/tests/manager_operations.ml @@ -678,13 +678,13 @@ module Memchecks = struct with_checks ~classification:`Absent ~should_propagate:false let check_balance ~__LOC__ {client; _} key amount = - let* json_bal = + let* bal = RPC.Client.call client @@ RPC.get_chain_block_context_contract_balance ~id:key.Account.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in if bal <> amount then Test.fail ~__LOC__ @@ -1213,13 +1213,13 @@ module Simple_transfers = struct ~tags:["transaction"; "transfer"] @@ fun protocol -> let* nodes = Helpers.init ~protocol () in - let* json_bal = + let* bal = RPC.Client.call nodes.main.client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap2.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in let* _ = Memchecks.with_branch_delayed_checks ~__LOC__ nodes @@ fun () -> Operation.inject_transfer @@ -1246,13 +1246,13 @@ module Simple_transfers = struct ~tags:["transaction"; "transfer"] @@ fun protocol -> let* nodes = Helpers.init ~protocol () in - let* json_bal = + let* bal = RPC.Client.call nodes.main.client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap2.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in let* _ = Memchecks.with_applied_checks ~__LOC__ @@ -1287,13 +1287,13 @@ module Simple_transfers = struct let* counter = Operation.get_counter nodes.main.client ~source:Constant.bootstrap2 in - let* json_bal = + let* bal = RPC.Client.call nodes.main.client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap2.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in let* _ = Memchecks.with_branch_refused_checks ~__LOC__ nodes @@ fun () -> Operation.inject_transfer @@ -1324,13 +1324,13 @@ module Simple_transfers = struct let* counter = Operation.get_counter nodes.main.client ~source:Constant.bootstrap2 in - let* json_bal = + let* bal = RPC.Client.call nodes.main.client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap2.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in let* _ = Memchecks.with_branch_delayed_checks ~__LOC__ nodes @@ fun () -> Operation.inject_transfer @@ -1359,13 +1359,13 @@ module Simple_transfers = struct ~tags:["transaction"; "transfer"] @@ fun protocol -> let* nodes = Helpers.init ~protocol () in - let* json_bal = + let* bal = RPC.Client.call nodes.main.client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap2.public_key_hash () in - let bal = JSON.as_int json_bal in + let bal = Tez.to_mutez bal in let* _ = Memchecks.with_refused_checks ~__LOC__ nodes @@ fun () -> Operation.inject_transfer diff --git a/tezt/tests/prevalidator.ml b/tezt/tests/prevalidator.ml index 75e77c172257..70a49c7beac3 100644 --- a/tezt/tests/prevalidator.ml +++ b/tezt/tests/prevalidator.ml @@ -1952,15 +1952,15 @@ module Revamped = struct ~tags:["mempool"; "precheck"; "empty"; "balance"] @@ fun protocol -> let* _node, client = Client.init_with_protocol ~protocol `Client () in - let* json_balance = + let* balance = RPC.Client.call client @@ RPC.get_chain_block_context_contract_balance ~id:Constant.bootstrap1.public_key_hash () in - let balance = JSON.as_string json_balance |> int_of_string in let* _op = - Operation.Manager.(inject [make ~fee:balance @@ transfer ()] client) + Operation.Manager.( + inject [make ~fee:(Tez.to_mutez balance) @@ transfer ()] client) in unit diff --git a/tezt/tests/sapling.ml b/tezt/tests/sapling.ml index 85bd6d745ad8..9453a407213a 100644 --- a/tezt/tests/sapling.ml +++ b/tezt/tests/sapling.ml @@ -241,11 +241,11 @@ module Helpers = struct return @@ Re.balance_diff ~dst:contract client_output let balance_tz1 (client, _contract) pkh = - let* json_bal = + let* balance_tez = RPC.Client.call client @@ RPC.get_chain_block_context_contract_balance ~id:pkh () in - return (JSON.as_int json_bal) + return (Tez.to_mutez balance_tez) end let contract = "sapling_contract.tz" diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 9fc78d7ed835..a82317222702 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -1784,15 +1784,15 @@ let commitments_reorgs protocol sc_rollup_node sc_rollup node client = type balances = {liquid : int; frozen : int} let contract_balances ~pkh client = - let* json_liquid = + let* liquid = RPC.Client.call client @@ RPC.get_chain_block_context_contract_balance ~id:pkh () in - let* frozen_json = + let* frozen = RPC.Client.call client @@ RPC.get_chain_block_context_contract_frozen_bonds ~id:pkh () in - return {liquid = JSON.as_int json_liquid; frozen = JSON.as_int frozen_json} + return {liquid = Tez.to_mutez liquid; frozen = Tez.to_mutez frozen} (** This helper allow to attempt recovering bond for SCORU rollup operator. if [expect_failure] is set to some string then, we expect the command to fail @@ -2521,12 +2521,12 @@ let test_refutation_scenario ?commitment_period ?challenge_window variant ~kind let* {stake_amount; _} = get_sc_rollup_constants client in Check.( - (JSON.as_int honest_deposit_json = Tez.to_mutez stake_amount) - int + (honest_deposit_json = stake_amount) + Tez.typ ~error_msg:"expecting deposit for honest participant = %R, got %L") ; Check.( - (JSON.as_int loser_deposit_json = 0) - int + (loser_deposit_json = Tez.zero) + Tez.typ ~error_msg:"expecting loss for dishonest participant = %R, got %L") ; Log.info "Checking that we can still retrieve state from rollup node" ; (* This is a way to make sure the rollup node did not crash *) diff --git a/tezt/tests/tx_rollup.ml b/tezt/tests/tx_rollup.ml index ca8b718c134d..56bc912e195d 100644 --- a/tezt/tests/tx_rollup.ml +++ b/tezt/tests/tx_rollup.ml @@ -1375,13 +1375,12 @@ let test_rollup_wrong_rejection_long_path = Process.check_error ~msg:(rex "tx_rollup_wrong_message_path") process let check_bond_is ~src client ~expected = - let* bond_json = + let* given = RPC.Client.call client @@ RPC.get_chain_block_context_contract_frozen_bonds ~id:src () in - let given = JSON.as_int bond_json in - Check.(given = expected) - Check.int + Check.(given = Tez.of_mutez_int expected) + Tez.typ ~error_msg:"Unexpected frozen bond for tx rollup. Expected %R. Got %L" ; unit -- GitLab From c8d47dfdf4263c18aa80056daf5f3d835e7f789c Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Tue, 27 Sep 2022 12:30:30 +0200 Subject: [PATCH 2/3] Tezt: translate [transfer_rpc] of [test_mockup.py] --- tests_python/tests_014/test_mockup.py | 27 ------------------- tests_python/tests_015/test_mockup.py | 27 ------------------- tests_python/tests_alpha/test_mockup.py | 27 ------------------- tezt/tests/mockup.ml | 35 ++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 82 deletions(-) diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index 19c74ace3920..764688c77e35 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -435,33 +435,6 @@ def test_create_mockup_config_show_init_roundtrip( ) -def test_transfer_rpc(mockup_client: Client): - """Variant of test_transfer that uses RPCs to get the balances.""" - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - transferred_mutz = transferred * 1000000 - - def get_balance(tz1): - res = mockup_client.rpc( - 'get', - f'chains/main/blocks/head/context/contracts/{tz1}/balance', - ) - return float(res) - - addresses = mockup_client.get_known_addresses() - giver_tz1 = addresses.wallet[giver] - recvr_tz1 = addresses.wallet[receiver] - giver_balance_before = get_balance(giver_tz1) - receiver_balance_before = get_balance(recvr_tz1) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = get_balance(giver_tz1) - receiver_balance_after = get_balance(recvr_tz1) - - assert giver_balance_after < giver_balance_before - transferred_mutz - assert receiver_balance_after == receiver_balance_before + transferred_mutz - - @pytest.mark.parametrize( 'protos', [(protocol.HASH, protocol.HASH), (protocol.HASH, "")], diff --git a/tests_python/tests_015/test_mockup.py b/tests_python/tests_015/test_mockup.py index 453686ad3402..50028f0f399c 100644 --- a/tests_python/tests_015/test_mockup.py +++ b/tests_python/tests_015/test_mockup.py @@ -508,33 +508,6 @@ def test_create_mockup_config_show_init_roundtrip( ) -def test_transfer_rpc(mockup_client: Client): - """Variant of test_transfer that uses RPCs to get the balances.""" - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - transferred_mutz = transferred * 1000000 - - def get_balance(tz1): - res = mockup_client.rpc( - 'get', - f'chains/main/blocks/head/context/contracts/{tz1}/balance', - ) - return float(res) - - addresses = mockup_client.get_known_addresses() - giver_tz1 = addresses.wallet[giver] - recvr_tz1 = addresses.wallet[receiver] - giver_balance_before = get_balance(giver_tz1) - receiver_balance_before = get_balance(recvr_tz1) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = get_balance(giver_tz1) - receiver_balance_after = get_balance(recvr_tz1) - - assert giver_balance_after < giver_balance_before - transferred_mutz - assert receiver_balance_after == receiver_balance_before + transferred_mutz - - @pytest.mark.parametrize( 'protos', [ diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index 9aeeeefc483b..154ea48aa2e4 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -508,33 +508,6 @@ def test_create_mockup_config_show_init_roundtrip( ) -def test_transfer_rpc(mockup_client: Client): - """Variant of test_transfer that uses RPCs to get the balances.""" - giver = "bootstrap1" - receiver = "bootstrap2" - transferred = 1.0 - transferred_mutz = transferred * 1000000 - - def get_balance(tz1): - res = mockup_client.rpc( - 'get', - f'chains/main/blocks/head/context/contracts/{tz1}/balance', - ) - return float(res) - - addresses = mockup_client.get_known_addresses() - giver_tz1 = addresses.wallet[giver] - recvr_tz1 = addresses.wallet[receiver] - giver_balance_before = get_balance(giver_tz1) - receiver_balance_before = get_balance(recvr_tz1) - mockup_client.transfer(transferred, giver, receiver) - giver_balance_after = get_balance(giver_tz1) - receiver_balance_after = get_balance(recvr_tz1) - - assert giver_balance_after < giver_balance_before - transferred_mutz - assert receiver_balance_after == receiver_balance_before + transferred_mutz - - @pytest.mark.parametrize( 'protos', [ diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index 64e4fd8180b1..9bdde86c1b87 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -879,6 +879,38 @@ let test_config_init_mockup_fail = Check.file_not_exists ~__LOC__ bootstrap_accounts ; unit +(* Variant of test_transfer that uses RPCs to get the balances. *) +let test_transfer_rpc = + Protocol.register_test + ~__FILE__ + ~title:"(Mockup) Mockup transfer RPC." + ~tags:["mockup"; "client"; "transfer"; "rpc"] + @@ fun protocol -> + let* client = Client.init_mockup ~protocol () in + let get_balance (key : Account.key) = + RPC.Client.call client + @@ RPC.get_chain_block_context_contract_balance ~id:key.public_key_hash () + in + let giver = Account.Bootstrap.keys.(0) in + let receiver = Account.Bootstrap.keys.(1) in + let amount = Tez.one in + let* giver_balance_before = get_balance giver in + let* receiver_balance_before = get_balance receiver in + let* () = + Client.transfer ~amount ~giver:giver.alias ~receiver:receiver.alias client + in + let* giver_balance_after = get_balance giver in + let* receiver_balance_after = get_balance receiver in + Check.(giver_balance_after < Tez.(giver_balance_before - amount)) + Tez.typ + ~__LOC__ + ~error_msg:"Expected giver balance < %R, got %L" ; + Check.(receiver_balance_after = Tez.(receiver_balance_before + amount)) + Tez.typ + ~__LOC__ + ~error_msg:"Expected receiver balance = %R, got %L" ; + unit + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -900,7 +932,8 @@ let register ~protocols = test_config_show_mockup protocols ; test_config_show_mockup_fail protocols ; test_config_init_mockup protocols ; - test_config_init_mockup_fail protocols + test_config_init_mockup_fail protocols ; + test_transfer_rpc protocols let register_global_constants ~protocols = test_register_global_constant_success protocols ; -- GitLab From e68b19ac08ef3b5301318e8b9f3bf5a4c98374eb Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Tue, 27 Sep 2022 12:23:57 +0200 Subject: [PATCH 3/3] Tezt: translate [protos_mix] of [test_mockup.py] --- tests_python/tests_014/test_mockup.py | 45 +--------------------- tests_python/tests_015/test_mockup.py | 47 ----------------------- tests_python/tests_alpha/test_mockup.py | 47 ----------------------- tezt/tests/mockup.ml | 51 ++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 139 deletions(-) diff --git a/tests_python/tests_014/test_mockup.py b/tests_python/tests_014/test_mockup.py index 764688c77e35..4179b8990d59 100644 --- a/tests_python/tests_014/test_mockup.py +++ b/tests_python/tests_014/test_mockup.py @@ -10,7 +10,7 @@ import json import os import tempfile -from typing import Any, List, Optional, Tuple +from typing import Any, Optional, Tuple import pytest from launchers.sandbox import Sandbox from client.client import Client @@ -433,46 +433,3 @@ def test_create_mockup_config_show_init_roundtrip( initial_bootstrap_accounts, protocol_constants, ) - - -@pytest.mark.parametrize( - 'protos', - [(protocol.HASH, protocol.HASH), (protocol.HASH, "")], -) -@pytest.mark.parametrize( - 'command', - [ - ["config", "show"], - ["config", "init"], - ["list", "known", "addresses"], - ["get", "balance", "for", "bootstrap1"], - ], -) -def test_proto_mix( - sandbox: Sandbox, protos: Tuple[str, str], command: List[str] -): - """ - This test covers 3 cases: - - 1/ When proto's second element equals the first member: - it tests that the command works. - 2/ When proto's second element is empty: - it tests that the correct mockup implementation is picked - (i.e. the one of the first element) and that the command works. - 3/ When protos' second element is not empty and differs from - the first member: it tests - that creating a mockup with a protocol and using it with another - protocol fails. - """ - proto1 = protos[0] - proto2 = protos[1] - with tempfile.TemporaryDirectory(prefix='octez-client.') as base_dir: - # Follow pattern of mockup_client fixture: - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup(protocol=proto1) - assert res.create_mockup_result == CreateMockupResult.OK - mock_client = sandbox.create_client(base_dir=base_dir, mode="mockup") - cmd = (["--protocol", proto2] if proto2 else []) + command - success = (proto2 == proto1) or (not proto2) - (_, _, return_code) = mock_client.run_generic(cmd, check=False) - assert (return_code == 0) == success diff --git a/tests_python/tests_015/test_mockup.py b/tests_python/tests_015/test_mockup.py index 50028f0f399c..e459cabf23ab 100644 --- a/tests_python/tests_015/test_mockup.py +++ b/tests_python/tests_015/test_mockup.py @@ -506,50 +506,3 @@ def test_create_mockup_config_show_init_roundtrip( initial_bootstrap_accounts, request.getfixturevalue(protocol_constants), ) - - -@pytest.mark.parametrize( - 'protos', - [ - (proto1, proto2) - for proto1 in [protocol.HASH, protocol.PREV_HASH] - for proto2 in [protocol.HASH, protocol.PREV_HASH, ""] - ], -) -@pytest.mark.parametrize( - 'command', - [ - ["config", "show"], - ["config", "init"], - ["list", "known", "addresses"], - ["get", "balance", "for", "bootstrap1"], - ], -) -def test_proto_mix( - sandbox: Sandbox, protos: Tuple[str, str], command: List[str] -): - """ - This test covers 3 cases: - - 1/ When proto's second element equals the first member: - it tests that the command works. - 2/ When proto's second element is empty: - it tests that the correct mockup implementation is picked - (i.e. the one of the first element) and that the command works. - 3/ When protos' second element is not empty and differs from - the first member: it tests - that creating a mockup with a protocol and using it with another - protocol fails. - """ - proto1 = protos[0] - proto2 = protos[1] - with tempfile.TemporaryDirectory(prefix='octez-client.') as base_dir: - # Follow pattern of mockup_client fixture: - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup(protocol=proto1) - assert res.create_mockup_result == CreateMockupResult.OK - mock_client = sandbox.create_client(base_dir=base_dir, mode="mockup") - cmd = (["--protocol", proto2] if proto2 else []) + command - success = (proto2 == proto1) or (not proto2) - (_, _, return_code) = mock_client.run_generic(cmd, check=False) - assert (return_code == 0) == success diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index 154ea48aa2e4..4d190f5d65c0 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -506,50 +506,3 @@ def test_create_mockup_config_show_init_roundtrip( initial_bootstrap_accounts, request.getfixturevalue(protocol_constants), ) - - -@pytest.mark.parametrize( - 'protos', - [ - (proto1, proto2) - for proto1 in [protocol.HASH, protocol.PREV_HASH] - for proto2 in [protocol.HASH, protocol.PREV_HASH, ""] - ], -) -@pytest.mark.parametrize( - 'command', - [ - ["config", "show"], - ["config", "init"], - ["list", "known", "addresses"], - ["get", "balance", "for", "bootstrap1"], - ], -) -def test_proto_mix( - sandbox: Sandbox, protos: Tuple[str, str], command: List[str] -): - """ - This test covers 3 cases: - - 1/ When proto's second element equals the first member: - it tests that the command works. - 2/ When proto's second element is empty: - it tests that the correct mockup implementation is picked - (i.e. the one of the first element) and that the command works. - 3/ When protos' second element is not empty and differs from - the first member: it tests - that creating a mockup with a protocol and using it with another - protocol fails. - """ - proto1 = protos[0] - proto2 = protos[1] - with tempfile.TemporaryDirectory(prefix='octez-client.') as base_dir: - # Follow pattern of mockup_client fixture: - unmanaged_client = sandbox.create_client(base_dir=base_dir) - res = unmanaged_client.create_mockup(protocol=proto1) - assert res.create_mockup_result == CreateMockupResult.OK - mock_client = sandbox.create_client(base_dir=base_dir, mode="mockup") - cmd = (["--protocol", proto2] if proto2 else []) + command - success = (proto2 == proto1) or (not proto2) - (_, _, return_code) = mock_client.run_generic(cmd, check=False) - assert (return_code == 0) == success diff --git a/tezt/tests/mockup.ml b/tezt/tests/mockup.ml index 9bdde86c1b87..5d465a5cdfdd 100644 --- a/tezt/tests/mockup.ml +++ b/tezt/tests/mockup.ml @@ -911,6 +911,54 @@ let test_transfer_rpc = ~error_msg:"Expected receiver balance = %R, got %L" ; unit +let test_proto_mix = + Protocol.register_test + ~__FILE__ + ~title:"(Mockup) Mockup mixed protocols." + ~tags:["mockup"; "client"; "transfer"; "rpc"] + @@ fun protocol -> + let protos1, protos2 = + match Protocol.previous_protocol protocol with + | Some previous_protocol -> + ( [protocol; previous_protocol], + [Some protocol; Some previous_protocol; None] ) + | None -> ([protocol], [Some protocol; None]) + in + Fun.flip Lwt_list.iter_s protos1 @@ fun proto1 -> + Fun.flip Lwt_list.iter_s protos2 @@ fun proto2 -> + (* This test covers 3 cases: + + 1/ When [proto2] equals [Some proto1]: it tests that the command works. + + 2/ When [proto2] is [None]: it tests that the correct + mockup implementation is picked (i.e. the one of [proto1]) + and that the command works. + + 3/ When [proto2] is [Some proto] such that [proto <> proto1]: + it tests that creating a mockup with a protocol and + using it with another protocol fails. *) + let* client1 = Client.init_mockup ~protocol:proto1 () in + let client2 = + Client.create_with_mode ~base_dir:(Client.base_dir client1) Mockup + in + Fun.flip + Lwt_list.iter_s + [ + ["config"; "show"]; + ["config"; "init"]; + ["list"; "known"; "addresses"]; + ["get"; "balance"; "for"; "bootstrap1"]; + ] + @@ fun cmd -> + match (proto1, proto2) with + | _, Some proto2 when proto1 = proto2 -> + Client.spawn_command ~protocol_hash:(Protocol.hash proto2) client2 cmd + |> Process.check + | _, None -> Client.spawn_command client2 cmd |> Process.check + | _, Some proto2 -> + Client.spawn_command ~protocol_hash:(Protocol.hash proto2) client2 cmd + |> Process.check_error + let register ~protocols = test_rpc_list protocols ; test_same_transfer_twice protocols ; @@ -933,7 +981,8 @@ let register ~protocols = test_config_show_mockup_fail protocols ; test_config_init_mockup protocols ; test_config_init_mockup_fail protocols ; - test_transfer_rpc protocols + test_transfer_rpc protocols ; + test_proto_mix protocols let register_global_constants ~protocols = test_register_global_constant_success protocols ; -- GitLab