From 86618b0ce851ef1c87f6d0837a28c346bb45d934 Mon Sep 17 00:00:00 2001 From: Elliot Cameron Date: Tue, 6 Aug 2019 17:04:43 -0400 Subject: [PATCH 1/2] Ledger: Add more ledger tests for proposal submission --- src/bin_flextesa/command_ledger_wallet.ml | 78 ++++++++++++----------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/bin_flextesa/command_ledger_wallet.ml b/src/bin_flextesa/command_ledger_wallet.ml index 8ce228eb5f42..dd43a416da05 100644 --- a/src/bin_flextesa/command_ledger_wallet.ml +++ b/src/bin_flextesa/command_ledger_wallet.ml @@ -158,6 +158,47 @@ let sign state ~client ~bytes () = ["sign"; "bytes"; "0x" ^ bytes; "for"; client.Tezos_client.Keyed.key_name] >>= fun _ -> return () +let proposal_submission_tests ~state ~ledger_account ~client () = + let expect_rejection (success, stdout) = + assert_ (not success) + >>= fun () -> + ( match + String.substr_index stdout ~pattern:"Conditions of use not satisfied" + with + | None -> failf "expected rejection but got '%s'" stdout + | Some _ -> return () ) + in + let expect_success (success, stdout) = + assert_ (not success) + >>= fun () -> + ( match + String.substr_index stdout + ~pattern:"not registered as valid delegate key" + with + | None -> failf "expected error that key is not registered as valid delegate" + | Some _ -> return () ) + in + let test_reject_and_accept prompt action = + ledger_prompt_notice_expectation state prompt `Fails + >>= action + >>= expect_rejection + >>= fun () -> ledger_prompt_notice_expectation state prompt `Succeeds + >>= action + >>= expect_success + in + let submit_proposals proposals () = + client_async_cmd state ~client:(client 0) + ~f:(fun proc -> find_and_print_signature_hash state proc#stdout) + ([ "submit"; "proposals"; "for" + ; Tezos_protocol.Account.pubkey_hash ledger_account + ] @ proposals @ + [ "--force" + ; "--verbose-signing" ]) + in + let single_proposal = "Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd" in + test_reject_and_accept EF.(wf "Submitting proposal %s" single_proposal) (submit_proposals [single_proposal]) + >>= fun () -> test_reject_and_accept EF.(wf "Submitting multi-protocol proposal submission") (submit_proposals [single_proposal; "Psd1ynUBhMZAeajwcZJAeq5NrxorM6UCU4GJqxZ7Bx2e9vUWB6z"]) + let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = Helpers.clear_root state >>= fun () -> @@ -200,43 +241,8 @@ let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = (Tezos_protocol.Account.pubkey_hash ledger_account)) (fun () -> Tezos_client.Keyed.initialize state signer >>= fun _ -> return () ) - >>= fun _ -> - let submit_proposals () = - client_async_cmd state ~client:(client 0) - ~f:(fun proc -> find_and_print_signature_hash state proc#stdout) - [ "submit"; "proposals"; "for" - ; Tezos_protocol.Account.pubkey_hash ledger_account - ; "Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd" - ; "Psd1ynUBhMZAeajwcZJAeq5NrxorM6UCU4GJqxZ7Bx2e9vUWB6z"; "--force" - ; "--verbose-signing" ] - in - ledger_prompt_notice_expectation state - EF.(wf "Submitting multi-protocol proposal submission") - `Fails - >>= submit_proposals - >>= fun (success, stdout) -> - assert_ (not success) - >>= fun () -> - ( match - String.substr_index stdout ~pattern:"Conditions of use not satisfied" - with - | None -> failf "expected rejection %s" stdout - | Some _ -> return () ) - >>= fun () -> - ledger_prompt_notice_expectation state - EF.(wf "Submitting multi-protocol proposal submission") - `Succeeds - >>= submit_proposals - >>= fun (success, stdout) -> - assert_ (not success) + >>= fun _ -> proposal_submission_tests ~state ~client ~ledger_account () >>= fun () -> - ( match - String.substr_index stdout - ~pattern:"not registered as valid delegate key" - with - | None -> failf "expected error that key is not registered as valid delegate" - | Some _ -> return () ) - >>= fun _ -> forge_batch_transactions state ~client:(client 0) ~src:(Tezos_protocol.Account.pubkey_hash ledger_account) ~dest:"tz2KZPgf2rshxNUBXFcTaCemik1LH1v9qz3F" ~n:50 () -- GitLab From ca608d68365332c9727c39ef4aeb629dfc806212 Mon Sep 17 00:00:00 2001 From: Elliot Cameron Date: Wed, 7 Aug 2019 17:26:20 -0400 Subject: [PATCH 2/2] f --- src/bin_flextesa/command_ledger_wallet.ml | 93 +++++++++++------------ 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/src/bin_flextesa/command_ledger_wallet.ml b/src/bin_flextesa/command_ledger_wallet.ml index dd43a416da05..1d9ce3d16e04 100644 --- a/src/bin_flextesa/command_ledger_wallet.ml +++ b/src/bin_flextesa/command_ledger_wallet.ml @@ -25,8 +25,7 @@ let find_and_print_signature_hash state stream = Re.( match exec_opt re lines with | None -> None - | Some matches -> Some (Group.get matches 1)) - in + | Some matches -> Some (Group.get matches 1)) in Asynchronous_result.Stream.fold (Lwt_io.read_lines stream) ~init:("", false) ~f:(fun (all_output_prev, showed_message_prev) line -> let all_output = all_output_prev ^ "\n" ^ line in @@ -37,7 +36,7 @@ let find_and_print_signature_hash state stream = Console.say state EF.(wf "Hash should be: %s" x) >>= fun () -> return true else return true ) - >>= fun showed_message -> return (all_output, showed_message) ) + >>= fun showed_message -> return (all_output, showed_message)) >>= fun (output, _) -> return output let ledger_prompt_notice state ~ef ?(button = `Checkmark) () = @@ -45,8 +44,7 @@ let ledger_prompt_notice state ~ef ?(button = `Checkmark) () = match button with | `Checkmark -> "✔" | `X -> "❌" - | `Both -> "❌ and ✔ at the same time" - in + | `Both -> "❌ and ✔ at the same time" in Console.say state EF.( desc (shout "Ledger-prompt") @@ -111,7 +109,7 @@ let get_chain_id state ~client = Tezos_client.rpc state ~client `Get ~path:"/chains/main/chain_id" >>= (function | `String x -> return x - | _ -> failf "Failed to parse chain_id JSON from node" ) + | _ -> failf "Failed to parse chain_id JSON from node") >>= fun chain_id_string -> return (Tezos_crypto.Chain_id.of_b58check_exn chain_id_string) @@ -141,7 +139,7 @@ let forge_batch_transactions state ~client ~src ~dest ~n ?(fee = 0.00126) () = ) ; ("counter", `String (string_of_int i)) ; ("gas_limit", `String (string_of_int 127)) - ; ("storage_limit", `String (string_of_int 277)) ] )) ) ] + ; ("storage_limit", `String (string_of_int 277)) ])) ) ] in Tezos_client.rpc state ~client ~path:"/chains/main/blocks/head/helpers/forge/operations" @@ -158,46 +156,46 @@ let sign state ~client ~bytes () = ["sign"; "bytes"; "0x" ^ bytes; "for"; client.Tezos_client.Keyed.key_name] >>= fun _ -> return () -let proposal_submission_tests ~state ~ledger_account ~client () = +let proposal_submission_tests ~state ~client ~src () = let expect_rejection (success, stdout) = assert_ (not success) >>= fun () -> - ( match - String.substr_index stdout ~pattern:"Conditions of use not satisfied" - with + match + String.substr_index stdout ~pattern:"Conditions of use not satisfied" + with | None -> failf "expected rejection but got '%s'" stdout - | Some _ -> return () ) - in + | Some _ -> return () in let expect_success (success, stdout) = assert_ (not success) >>= fun () -> - ( match - String.substr_index stdout - ~pattern:"not registered as valid delegate key" - with - | None -> failf "expected error that key is not registered as valid delegate" - | Some _ -> return () ) - in + match + String.substr_index stdout + ~pattern:"not registered as valid delegate key" + with + | None -> + failf "expected error that key is not registered as valid delegate" + | Some _ -> return () in let test_reject_and_accept prompt action = ledger_prompt_notice_expectation state prompt `Fails - >>= action - >>= expect_rejection - >>= fun () -> ledger_prompt_notice_expectation state prompt `Succeeds - >>= action - >>= expect_success - in + >>= action >>= expect_rejection + >>= fun () -> + ledger_prompt_notice_expectation state prompt `Succeeds + >>= action >>= expect_success in let submit_proposals proposals () = client_async_cmd state ~client:(client 0) ~f:(fun proc -> find_and_print_signature_hash state proc#stdout) - ([ "submit"; "proposals"; "for" - ; Tezos_protocol.Account.pubkey_hash ledger_account - ] @ proposals @ - [ "--force" - ; "--verbose-signing" ]) - in + ( ["submit"; "proposals"; "for"; src] + @ proposals + @ ["--force"; "--verbose-signing"] ) in let single_proposal = "Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd" in - test_reject_and_accept EF.(wf "Submitting proposal %s" single_proposal) (submit_proposals [single_proposal]) - >>= fun () -> test_reject_and_accept EF.(wf "Submitting multi-protocol proposal submission") (submit_proposals [single_proposal; "Psd1ynUBhMZAeajwcZJAeq5NrxorM6UCU4GJqxZ7Bx2e9vUWB6z"]) + test_reject_and_accept + EF.(wf "Submitting proposal %s" single_proposal) + (submit_proposals [single_proposal]) + >>= fun () -> + test_reject_and_accept + EF.(wf "Submitting multi-protocol proposal submission") + (submit_proposals + [single_proposal; "Psd1ynUBhMZAeajwcZJAeq5NrxorM6UCU4GJqxZ7Bx2e9vUWB6z"]) let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = Helpers.clear_root state @@ -225,8 +223,7 @@ let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = Interactive_test.Pauser.generic state EF.[af "About to really start playing"] >>= fun () -> let client n = - Tezos_client.of_node ~exec:client_exec (List.nth_exn nodes n) - in + Tezos_client.of_node ~exec:client_exec (List.nth_exn nodes n) in let signer = Tezos_client.Keyed.make (client 0) ~key_name:"ledgered" ~secret_key:uri in @@ -240,8 +237,9 @@ let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = uri (client 0).Tezos_client.id (Tezos_protocol.Account.pubkey_hash ledger_account)) (fun () -> - Tezos_client.Keyed.initialize state signer >>= fun _ -> return () ) - >>= fun _ -> proposal_submission_tests ~state ~client ~ledger_account () + Tezos_client.Keyed.initialize state signer >>= fun _ -> return ()) + >>= fun _ -> + proposal_submission_tests ~state ~client ~src:signer.key_name () >>= fun () -> forge_batch_transactions state ~client:(client 0) ~src:(Tezos_protocol.Account.pubkey_hash ledger_account) @@ -252,8 +250,7 @@ let run state ~node_exec ~client_exec ~admin_exec ~size ~base_port ~uri () = `Hex batch_transaction_bytes |> Hex.to_bytes |> Tezos_stdlib.MBytes.of_bytes |> (fun x -> [x]) - |> Blake2B.hash_bytes |> Blake2B.to_string |> Base58.raw_encode) - in + |> Blake2B.hash_bytes |> Blake2B.to_string |> Base58.raw_encode) in with_ledger_test_reject_and_succeed state EF.( wf "Signing batch of transaction: Unrecognized Operation - Sign Hash %s" @@ -267,17 +264,17 @@ let cmd ~pp_error () = Test_command_line.Run_command.make ~pp_error ( pure (fun uri - node_exec - client_exec - admin_exec - size - (`Base_port base_port) - state - -> + node_exec + client_exec + admin_exec + size + (`Base_port base_port) + state + -> ( state , Interactive_test.Pauser.run_test ~pp_error state (run state ~node_exec ~size ~admin_exec ~base_port ~client_exec - ~uri) ) ) + ~uri) )) $ Arg.( required (pos 0 (some string) None -- GitLab