From 170411cf25766ee010ec7618b22063effbdc21a9 Mon Sep 17 00:00:00 2001 From: Quantifier Date: Tue, 4 Jul 2023 22:45:50 +0000 Subject: [PATCH] (test exec) Update with new common functions and modules --- .../test_executive/chain_reliability_test.ml | 7 +- src/app/test_executive/delegation_test.ml | 21 +- src/app/test_executive/gossip_consistency.ml | 4 +- src/app/test_executive/payments_test.ml | 10 +- .../test_executive/peers_reliability_test.ml | 25 +- src/app/test_executive/test_common.ml | 275 ++++++++++-------- src/app/test_executive/test_common.mli | 153 ++++++---- .../test_executive/verification_key_update.ml | 10 +- src/app/test_executive/zkapps.ml | 32 +- src/app/test_executive/zkapps_nonce_test.ml | 11 +- src/app/test_executive/zkapps_timing.ml | 35 ++- 11 files changed, 298 insertions(+), 285 deletions(-) diff --git a/src/app/test_executive/chain_reliability_test.ml b/src/app/test_executive/chain_reliability_test.ml index e970a3ac6d2..085cad68ea7 100644 --- a/src/app/test_executive/chain_reliability_test.ml +++ b/src/app/test_executive/chain_reliability_test.ml @@ -29,7 +29,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let module Node = Network.Node in let open Malleable_error.Let_syntax in let logger = Logger.create ~prefix:(test_name ^ "test: ") () in - let all_nodes = Network.all_nodes network in + let all_nodes = all_nodes network in let%bind () = Wait_for.all_nodes_to_initialize t network in let node_a = get_bp_node network "node-a" in let node_b = get_bp_node network "node-b" in @@ -75,7 +75,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let fee = Currency.Fee.of_mina_string_exn "1" in [%log info] "will now send %d payments" num_payments ; let%bind hashlist = - send_payments ~logger ~sender_pub_key ~receiver_pub_key + Payment_util.send_n ~logger ~sender_pub_key ~receiver_pub_key ~node:sender_bp ~fee ~amount num_payments in [%log info] "sending payments done. will now wait for payments" ; @@ -89,8 +89,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "common prefix of all nodes is no farther back than 1 block" (* the common prefix test relies on at least 4 blocks having been produced. previous sections altogether have already produced 4, so no further block production is needed. if previous sections change, then this may need to be re-adjusted*) (let%bind (labeled_chains : (string * string list) list) = - Malleable_error.List.map (Core.String.Map.data all_nodes) - ~f:(fun node -> + Malleable_error.List.map all_nodes ~f:(fun node -> let%map chain = Network.Node.must_get_best_chain ~logger node in (Node.id node, List.map ~f:(fun b -> b.state_hash) chain) ) in diff --git a/src/app/test_executive/delegation_test.ml b/src/app/test_executive/delegation_test.ml index b103f46ba5f..54506c0f20c 100644 --- a/src/app/test_executive/delegation_test.ml +++ b/src/app/test_executive/delegation_test.ml @@ -27,23 +27,16 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let run network t = let open Malleable_error.Let_syntax in let logger = Logger.create ~prefix:(test_name ^ "test: ") () in - (* fee for user commands *) - let fee = Currency.Fee.of_nanomina_int_exn 10_000_000 in let%bind () = Wait_for.all_nodes_to_initialize t network in let node_a = get_bp_node network "node-a" in let node_b = get_bp_node network "node-b" in let%bind () = section "Delegate all tokens from node_b to node_a" - (let delegation_receiver = node_a in - let%bind delegation_receiver_pub_key = - pub_key_of_node delegation_receiver - in - let delegation_sender = node_b in - let%bind delegation_sender_pub_key = - pub_key_of_node delegation_sender - in + (let%bind delegation_receiver_pub_key = pub_key_of_node node_a in + let%bind delegation_sender_pub_key = pub_key_of_node node_b in + let fee = Currency.Fee.of_nanomina_int_exn 10_000_000 in let%bind { hash; _ } = - Network.Node.must_send_delegation ~logger delegation_sender + Network.Node.must_send_delegation ~logger node_b ~sender_pub_key:delegation_sender_pub_key ~receiver_pub_key:delegation_receiver_pub_key ~fee in @@ -51,9 +44,5 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~node_included_in:`Any_node ) in section_hard "Running replayer" - (let%bind logs = - Network.Node.run_replayer ~logger - (List.hd_exn @@ Core.String.Map.data (Network.archive_nodes network)) - in - check_replayer_logs ~logger logs ) + (Archive_node.run_and_check_replayer ~logger network) end diff --git a/src/app/test_executive/gossip_consistency.ml b/src/app/test_executive/gossip_consistency.ml index a95370520a0..f8d6393fa8a 100644 --- a/src/app/test_executive/gossip_consistency.ml +++ b/src/app/test_executive/gossip_consistency.ml @@ -38,8 +38,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let amount = Currency.Amount.of_nanomina_int_exn 10_000_000 in [%log info] "will now send %d payments" num_payments ; let%bind hashlist = - send_payments ~logger ~sender_pub_key ~receiver_pub_key ~node:sender_bp - ~fee ~amount num_payments + Payment_util.send_n ~logger ~sender_pub_key ~receiver_pub_key + ~node:sender_bp ~fee ~amount num_payments in [%log info] "sending payments done. will now wait for payments" ; let%bind () = diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 72d5b2c0c58..ab2c07ee399 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -436,7 +436,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Hence, 6*2 = 12 transactions untill we get the first snarked ledger. 2 successful txn are sent in the prior course of this test, so spamming out at least 10 more here will trigger a ledger proof to be emitted *) - send_payments ~logger ~sender_pub_key ~receiver_pub_key + Payment_util.send_n ~logger ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee ~node:sender 10 in Wait_for.ledger_proofs_emitted_since_genesis t ~test_config:config @@ -515,7 +515,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = untimed_node_a in let%bind sender_pub_key = pub_key_of_node sender in let%bind _ = - send_payments ~logger ~sender_pub_key ~receiver_pub_key + Payment_util.send_n ~logger ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee ~node:sender 12 in Wait_for.ledger_proofs_emitted_since_genesis t ~num_proofs:2 @@ -574,9 +574,5 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct config.snark_worker_fee ) in section_hard "running replayer" - (let%bind logs = - Network.Node.run_replayer ~logger - (List.hd_exn @@ (Network.archive_nodes network |> Core.Map.data)) - in - check_replayer_logs ~logger logs ) + (Archive_node.run_and_check_replayer ~logger network) end diff --git a/src/app/test_executive/peers_reliability_test.ml b/src/app/test_executive/peers_reliability_test.ml index 9ad34cbcaef..8ad21a6c628 100644 --- a/src/app/test_executive/peers_reliability_test.ml +++ b/src/app/test_executive/peers_reliability_test.ml @@ -27,16 +27,13 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct } let run network t = - let open Network in + let module Node = Network.Node in let open Malleable_error.Let_syntax in let logger = Logger.create ~prefix:(test_name ^ " test: ") () in - let all_nodes = Network.all_nodes network in + let all_nodes = all_nodes network in [%log info] "peers_list" ~metadata: - [ ( "peers" - , `List - (List.map (Core.String.Map.data all_nodes) ~f:(fun n -> - `String (Node.id n) ) ) ) + [ ("peers", `List (List.map all_nodes ~f:(fun n -> `String (Node.id n)))) ] ; let node_a = get_bp_node network "node-a" in let node_b = get_bp_node network "node-b" in @@ -54,12 +51,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Time.Span.of_ms (20. *. 60. *. 1000.)) ) ) in (* let%bind () = wait_for t (Wait_condition.nodes_to_initialize [ node_c ]) in *) - let%bind () = - wait_for t - (Wait_condition.nodes_to_initialize (Core.String.Map.data all_nodes)) - in + let%bind () = Wait_for.all_nodes_to_initialize t network in let%bind initial_connectivity_data = - fetch_connectivity_data ~logger (Core.String.Map.data all_nodes) + fetch_connectivity_data ~logger all_nodes in let%bind () = section "network is fully connected upon initialization" @@ -83,9 +77,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~amount:(Currency.Amount.of_nanomina_int_exn 1_000_000) ~fee:(Currency.Fee.of_nanomina_int_exn 10_000_000) in - wait_for t - (Wait_condition.signed_command_to_be_included_in_frontier ~txn_hash - ~node_included_in:(`Node node_c) ) ) + Wait_for.signed_command_to_be_included_in_frontier t ~txn_hash + ~node_included_in:(`Node node_c) ) in let zkapp_account_keypair = Signature_lib.Keypair.create () in let%bind () = @@ -128,7 +121,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~constraint_constants:(Network.constraint_constants network) parties_spec in - let%bind () = Zkapp.send ~logger node_c parties_create_accounts in + let%bind () = Zkapp_util.send ~logger node_c parties_create_accounts in wait_for_zkapp parties_create_accounts ) in let%bind () = @@ -183,7 +176,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "network is fully connected after one node was restarted" (let%bind () = Malleable_error.lift (after (Time.Span.of_sec 240.0)) in let%bind final_connectivity_data = - fetch_connectivity_data ~logger (Core.String.Map.data all_nodes) + fetch_connectivity_data ~logger all_nodes in assert_peers_completely_connected final_connectivity_data ) end diff --git a/src/app/test_executive/test_common.ml b/src/app/test_executive/test_common.ml index 07b5f9a9516..dbf4bbae7a7 100644 --- a/src/app/test_executive/test_common.ml +++ b/src/app/test_executive/test_common.ml @@ -20,28 +20,95 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in go n - let send_payments ~logger ~sender_pub_key ~receiver_pub_key ~amount ~fee ~node - n = - let open Malleable_error.Let_syntax in - let rec go n hashlist = - if n = 0 then return hashlist - else - let%bind hash = - let%map { hash; nonce; _ } = - Network.Node.must_send_payment ~logger ~sender_pub_key - ~receiver_pub_key ~amount ~fee node + module Payment_util = struct + let send_n ~logger ~sender_pub_key ~receiver_pub_key ~amount ~fee ~node n = + let open Malleable_error.Let_syntax in + let rec go n hashlist = + if n = 0 then return hashlist + else + let%bind hash = + let%map { hash; nonce; _ } = + Network.Node.must_send_payment ~logger ~sender_pub_key + ~receiver_pub_key ~amount ~fee node + in + [%log info] + "sending multiple payments: payment #%d sent with hash of %s and \ + nonce of %d." + n + (Transaction_hash.to_base58_check hash) + (Unsigned.UInt32.to_int nonce) ; + hash in - [%log info] - "sending multiple payments: payment #%d sent with hash of %s and \ - nonce of %d." - n - (Transaction_hash.to_base58_check hash) - (Unsigned.UInt32.to_int nonce) ; - hash - in - go (n - 1) (List.append hashlist [ hash ]) - in - go n [] + go (n - 1) (List.append hashlist [ hash ]) + in + go n [] + + let send_invalid ~logger node ~sender_pub_key ~receiver_pub_key ~amount ~fee + ~nonce ~memo ~valid_until ~raw_signature ~expected_failure : + unit Malleable_error.t = + [%log info] "Sending payment, expected to fail" ; + let expected_failure = String.lowercase expected_failure in + match%bind.Deferred + Network.Node.send_payment_with_raw_sig ~logger node ~sender_pub_key + ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until + ~raw_signature + with + | Ok _ -> + [%log error] "Payment succeeded, expected error \"%s\"" + expected_failure ; + Malleable_error.hard_error_format + "Payment transaction succeeded, expected error \"%s\"" + expected_failure + | Error err -> + let err_str = Error.to_string_mach err |> String.lowercase in + if String.is_substring ~substring:expected_failure err_str then ( + [%log info] "Payment failed as expected" + ~metadata:[ ("error", `String err_str) ] ; + Malleable_error.return () ) + else ( + [%log error] + "Error sending payment, for a reason other than the expected \ + \"%s\"" + expected_failure + ~metadata:[ ("error", `String err_str) ] ; + Malleable_error.hard_error_format + "Payment failed: %s, but expected \"%s\"" err_str expected_failure + ) + + (* TODO: must_send_payment_with_raw_sig *) + end + + module Account_util = struct + let get_permissions ~logger node account_id = + [%log info] "Getting permissions for account" + ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; + match%bind.Deferred + Network.Node.get_account_permissions ~logger node ~account_id + with + | Ok permissions -> + [%log info] "Got account permissions" ; + Malleable_error.return permissions + | Error err -> + let err_str = Error.to_string_mach err in + [%log error] "Error getting account permissions" + ~metadata:[ ("error", `String err_str) ] ; + Malleable_error.hard_error (Error.of_string err_str) + + let get_update ~logger node account_id = + [%log info] "Getting update for account" + ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; + match%bind.Deferred + Network.Node.get_account_update ~logger node ~account_id + with + | Ok update -> + [%log info] "Got account update" ; + Malleable_error.return update + | Error err -> + let err_str = Error.to_string_mach err in + [%log error] "Error getting account update" + ~metadata:[ ("error", `String err_str) ] ; + Malleable_error.hard_error (Error.of_string err_str) + end module Wait_for = struct let nodes_to_initialize dsl nodes = @@ -71,10 +138,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = let hash = List.hd_exn hashlist in let%map () = - Dsl.( - wait_for dsl - @@ Wait_condition.signed_command_to_be_included_in_frontier - ~txn_hash:hash ~node_included_in:`Any_node) + wait_for dsl + @@ Wait_condition.signed_command_to_be_included_in_frontier + ~txn_hash:hash ~node_included_in:`Any_node in [%log info] "wait for multiple payments: payment #%d with hash %s \ @@ -90,8 +156,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let signed_command_to_be_included_in_frontier dsl ~txn_hash ~node_included_in = wait_for dsl - (Wait_condition.signed_command_to_be_included_in_frontier ~txn_hash - ~node_included_in ) + @@ Wait_condition.signed_command_to_be_included_in_frontier ~txn_hash + ~node_included_in let with_timeouts dsl ~condition ~soft_timeout ~hard_timeout = wait_for dsl @@ -220,14 +286,16 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~connected_peers ) let assert_peers_cant_be_partitioned ~max_disconnections nodes_and_responses = - (* this check checks that the network does NOT become partitioned into isolated subgraphs, even if n nodes are hypothetically removed from the network.*) + (* checks that the network does NOT become partitioned into isolated subgraphs, + even if n nodes are hypothetically removed from the network.*) let _, responses = List.unzip nodes_and_responses in let open Graph_algorithms in let () = Out_channel.with_file "/tmp/network-graph.dot" ~f:(fun c -> G.output_graph c (graph_of_adjacency_list responses) ) in - (* Check that the network cannot be disconnected by removing up to max_disconnections number of nodes. *) + (* checks that the network cannot be disconnected by removing up to + [max_disconnections] many nodes. *) match Nat.take (Graph_algorithms.connectivity (module String) responses) @@ -239,7 +307,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct | `Ok -> Malleable_error.return () - module Zkapp = struct + module Zkapp_util = struct let send_batch ~logger node zkapp_commands = List.iter zkapp_commands ~f:(fun zkapp_command -> [%log info] "Sending zkApp" @@ -293,84 +361,22 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "ZkApp transaction failed: %s, but expected \"%s\"" err_str substring ) - let send_invalid_payment ~logger node ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature ~expected_failure - : unit Malleable_error.t = - [%log info] "Sending payment, expected to fail" ; - let expected_failure = String.lowercase expected_failure in + let get_pooled_zkapp_commands ~logger node ~pk = + [%log info] "Getting pooled zkApp commands" + ~metadata: + [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pk) ] ; match%bind.Deferred - Network.Node.send_payment_with_raw_sig ~logger node ~sender_pub_key - ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until - ~raw_signature + Network.Node.get_pooled_zkapp_commands ~logger node ~pk with - | Ok _ -> - [%log error] "Payment succeeded, expected error \"%s\"" - expected_failure ; - Malleable_error.hard_error_format - "Payment transaction succeeded, expected error \"%s\"" - expected_failure - | Error err -> - let err_str = Error.to_string_mach err |> String.lowercase in - if String.is_substring ~substring:expected_failure err_str then ( - [%log info] "Payment failed as expected" - ~metadata:[ ("error", `String err_str) ] ; - Malleable_error.return () ) - else ( - [%log error] - "Error sending payment, for a reason other than the expected \ - \"%s\"" - expected_failure - ~metadata:[ ("error", `String err_str) ] ; - Malleable_error.hard_error_format - "Payment failed: %s, but expected \"%s\"" err_str expected_failure - ) - - let get_account_permissions ~logger node account_id = - [%log info] "Getting permissions for account" - ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; - match%bind.Deferred - Network.Node.get_account_permissions ~logger node ~account_id - with - | Ok permissions -> - [%log info] "Got account permissions" ; - Malleable_error.return permissions - | Error err -> - let err_str = Error.to_string_mach err in - [%log error] "Error getting account permissions" - ~metadata:[ ("error", `String err_str) ] ; - Malleable_error.hard_error (Error.of_string err_str) - - let get_account_update ~logger node account_id = - [%log info] "Getting update for account" - ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; - match%bind.Deferred - Network.Node.get_account_update ~logger node ~account_id - with - | Ok update -> - [%log info] "Got account update" ; - Malleable_error.return update + | Ok zkapp_commands -> + [%log info] "Got pooled zkApp commands" ; + Malleable_error.return zkapp_commands | Error err -> let err_str = Error.to_string_mach err in - [%log error] "Error getting account update" + [%log error] "Error getting pooled zkApp commands" ~metadata:[ ("error", `String err_str) ] ; Malleable_error.hard_error (Error.of_string err_str) - (* let get_pooled_zkapp_commands ~logger node ~pk = - [%log info] "Getting pooled zkApp commands" - ~metadata: - [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pk) ] ; - match%bind.Deferred - Network.Node.get_pooled_zkapp_commands ~logger node ~pk - with - | Ok zkapp_commands -> - [%log info] "Got pooled zkApp commands" ; - Malleable_error.return zkapp_commands - | Error err -> - let err_str = Error.to_string_mach err in - [%log error] "Error getting pooled zkApp commands" - ~metadata:[ ("error", `String err_str) ] ; - Malleable_error.hard_error (Error.of_string err_str) *) - let compatible_item req_item ledg_item ~equal = match (req_item, ledg_item) with | Mina_base.Zkapp_basic.Set_or_keep.Keep, _ -> @@ -448,32 +454,43 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~f:Fn.id end - (* [logs] is a string containing the entire replayer output *) - let check_replayer_logs ~logger logs = - let log_level_substring level = sprintf {|"level":"%s"|} level in - let error_log_substring = log_level_substring "Error" in - let fatal_log_substring = log_level_substring "Fatal" in - let info_log_substring = log_level_substring "Info" in - let split_logs = String.split logs ~on:'\n' in - let error_logs = - split_logs - |> List.filter ~f:(fun log -> - String.is_substring log ~substring:error_log_substring - || String.is_substring log ~substring:fatal_log_substring ) - in - let info_logs = - split_logs - |> List.filter ~f:(fun log -> - String.is_substring log ~substring:info_log_substring ) - in - if Mina_stdlib.List.Length.Compare.(info_logs < 25) then - Malleable_error.hard_error_string - (sprintf "Replayer output contains suspiciously few (%d) Info logs" - (List.length info_logs) ) - else if List.is_empty error_logs then ( - [%log info] "The replayer encountered no errors" ; - Malleable_error.return () ) - else - let error = String.concat error_logs ~sep:"\n " in - Malleable_error.hard_error_string ("Replayer errors:\n " ^ error) + module Archive_node = struct + let run_replayer ~logger network = + Network.Node.run_replayer ~logger + @@ List.hd_exn (Network.archive_nodes network |> Core.Map.data) + + (* [logs] is a string containing the entire replayer output *) + let check_replayer_logs ~logger logs = + let log_level_substring level = sprintf {|"level":"%s"|} level in + let error_log_substring = log_level_substring "Error" in + let fatal_log_substring = log_level_substring "Fatal" in + let info_log_substring = log_level_substring "Info" in + let split_logs = String.split logs ~on:'\n' in + let error_logs = + split_logs + |> List.filter ~f:(fun log -> + String.is_substring log ~substring:error_log_substring + || String.is_substring log ~substring:fatal_log_substring ) + in + let info_logs = + split_logs + |> List.filter ~f:(fun log -> + String.is_substring log ~substring:info_log_substring ) + in + if Mina_stdlib.List.Length.Compare.(info_logs < 25) then + Malleable_error.hard_error_string + (sprintf "Replayer output contains suspiciously few (%d) Info logs" + (List.length info_logs) ) + else if List.is_empty error_logs then ( + [%log info] "The replayer encountered no errors" ; + Malleable_error.return () ) + else + let error = String.concat error_logs ~sep:"\n " in + Malleable_error.hard_error_string ("Replayer errors:\n " ^ error) + + let run_and_check_replayer ~logger network = + let open Malleable_error.Let_syntax in + let%bind logs = run_replayer ~logger network in + check_replayer_logs ~logger logs + end end diff --git a/src/app/test_executive/test_common.mli b/src/app/test_executive/test_common.mli index db23b88b5d7..5f5c515ad25 100644 --- a/src/app/test_executive/test_common.mli +++ b/src/app/test_executive/test_common.mli @@ -7,17 +7,60 @@ module Make : functor -> f:(unit -> unit Integration_test_lib.Malleable_error.t) -> unit Integration_test_lib.Malleable_error.t - (** TODO: [send_payments] *) - val send_payments : - logger:Logger.t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> amount:Currency.Amount.t - -> fee:Currency.Fee.t - -> node:Inputs.Engine.Network.Node.t - -> int - -> Mina_transaction.Transaction_hash.t list - Integration_test_lib.Malleable_error.t + module Payment_util : sig + (** [send_n ~logger ~sender_pub_key ~receiver_pub_key ~amount ~fee ~node n] + [node] attempts to send [n] payments of [amount] from [sender_pub_key] to + [receiver_pub_key] paying [fee] for each, logs progress to [logger] *) + val send_n : + logger:Logger.t + -> sender_pub_key:Signature_lib.Public_key.Compressed.t + -> receiver_pub_key:Signature_lib.Public_key.Compressed.t + -> amount:Currency.Amount.t + -> fee:Currency.Fee.t + -> node:Inputs.Engine.Network.Node.t + -> int + -> Mina_transaction.Transaction_hash.t list + Integration_test_lib.Malleable_error.t + + (** TODO: [send_invalid ~logger node ~sender_pub_key ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature ~expected_failure]*) + val send_invalid : + logger:Logger.t + -> Inputs.Engine.Network.Node.t + -> sender_pub_key:Signature_lib.Public_key.Compressed.t + -> receiver_pub_key:Signature_lib.Public_key.Compressed.t + -> amount:Currency.Amount.t + -> fee:Currency.Fee.t + -> nonce:Unsigned.uint32 + -> memo:string + -> valid_until:Mina_numbers.Global_slot_since_genesis.t + -> raw_signature:string + -> expected_failure:string + -> unit Integration_test_lib.Malleable_error.t + end + + module Account_util : sig + (** TODO: [get_permissions ~logger node account_id]*) + val get_permissions : + logger:Logger.t + -> Inputs.Engine.Network.Node.t + -> Mina_base.Account_id.t + -> ( Mina_base.Permissions.t + Integration_test_lib.Malleable_error.Result_accumulator.t + , Integration_test_lib.Malleable_error.Hard_fail.t ) + result + Async.Deferred.t + + (** TODO: [get_update ~logger node account_id]*) + val get_update : + logger:Logger.t + -> Inputs.Engine.Network.Node.t + -> Mina_base.Account_id.t + -> ( Mina_base.Account_update.Update.t + Integration_test_lib.Malleable_error.Result_accumulator.t + , Integration_test_lib.Malleable_error.Hard_fail.t ) + result + Async.Deferred.t + end module Wait_for : sig (** [nodes_to_initialize dsl nodes] uses [dsl]'s wait condition to wait for [nodes] to initialize *) @@ -57,14 +100,17 @@ module Make : functor -> int -> unit Integration_test_lib.Malleable_error.t - (** TODO: [signed_command_to_be_included_in_frontier dsl ~txn_hash ~node_included_in] *) + (** [signed_command_to_be_included_in_frontier dsl ~txn_hash ~node_included_in] + uses [dsl]'s wait condition to wait for the signed command with transaction + hash [txn_hash] to be included in [node_included_in] *) val signed_command_to_be_included_in_frontier : Inputs.Dsl.t -> txn_hash:Mina_transaction.Transaction_hash.t -> node_included_in:[ `Any_node | `Node of Inputs.Engine.Network.Node.t ] -> unit Integration_test_lib.Malleable_error.t - (** TODO: [with_timeouts dsl ~condition ~soft_timeout ~hard_timeout] *) + (** [with_timeouts dsl ~condition ~soft_timeout ~hard_timeout] uses [dsl]'s wait + condition to wait for [condition] with a [soft_timeout] and a [hard_timeout] *) val with_timeouts : Inputs.Dsl.t -> condition:Inputs.Dsl.Wait_condition.t @@ -72,7 +118,10 @@ module Make : functor -> hard_timeout:Integration_test_lib.Network_time_span.t -> unit Integration_test_lib.Malleable_error.t - (** [zkapp_to_be_included_in_frontier] *) + (** [zkapp_to_be_included_in_frontier dsl ~has_failures ~zkapp_command ~soft_slots] + uses [dsl]'s wait condition to wait for [zkapp_command] to be included in the + transition frontier with a soft timeout equal to the span of [soft_slots] slots + and a hard timeout equal to the span of [2 * soft_slots] slots *) val zkapp_to_be_included_in_frontier : Inputs.Dsl.t -> has_failures:bool @@ -107,7 +156,7 @@ module Make : functor Inputs.Engine.Network.Node.t -> Signature_lib.Private_key.t Integration_test_lib.Malleable_error.t - (** TODO: [check_common_prefixes ~tolerance ~logger ...]*) + (** TODO: [check_common_prefixes ~tolerance ~logger chains]*) val check_common_prefixes : tolerance:int -> logger:Logger.t @@ -121,22 +170,23 @@ module Make : functor -> (Inputs.Engine.Network.Node.t * (string * string list)) list Integration_test_lib.Malleable_error.t - (** TODO: [assert_peers_completely_connected ...]*) + (** TODO: [assert_peers_completely_connected nodes_and_responses]*) val assert_peers_completely_connected : (Inputs.Engine.Network.Node.t * (string * string list)) list -> unit Integration_test_lib.Malleable_error.t - (** TODO: [assert_peers_cant_be_partitioned ~max_disconnection ...]*) + (** TODO: [assert_peers_cant_be_partitioned ~max_disconnection nodes_and_responses]*) val assert_peers_cant_be_partitioned : max_disconnections:int - -> ('a * (string * string list)) list + -> (_ * (string * string list)) list -> ( unit Integration_test_lib.Malleable_error.Result_accumulator.t , Integration_test_lib.Malleable_error.Hard_fail.t ) result Async.Deferred.t - module Zkapp : sig - (** TODO: [send_batch ~logger node zkapp_command]*) + module Zkapp_util : sig + (** [send_batch ~logger node zkapp_commands] returns the result of sending + all commands in [zkapp_commands] *) val send_batch : logger:Logger.t -> Inputs.Engine.Network.Node.t @@ -146,7 +196,8 @@ module Make : functor result Async.Deferred.t - (** TODO: [send ~logger node zkapp_command]*) + (** [send ~logger node zkapp_command] returns the result of [node] + sending the [zkapp_command] to the network, logs with [logger] *) val send : logger:Logger.t -> Inputs.Engine.Network.Node.t @@ -156,7 +207,9 @@ module Make : functor result Async.Deferred.t - (** TODO: [send_invalid ~logger node zkapp_command ...]*) + (** [send_invalid ~logger node zkapp_command substring_of_error_msg] + returns the result of [node] sending an invalid [zkapp_command] + expecting error [substring_of_error_msg], logs with [logger] *) val send_invalid : logger:Logger.t -> Inputs.Engine.Network.Node.t @@ -167,44 +220,18 @@ module Make : functor result Async.Deferred.t - (** TODO: [send_invalid_payment ~logger node ~sender_pub_key ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature ~expected_failure]*) - val send_invalid_payment : - logger:Logger.t - -> Inputs.Engine.Network.Node.t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> amount:Currency.Amount.t - -> fee:Currency.Fee.t - -> nonce:Unsigned.uint32 - -> memo:string - -> valid_until:Mina_numbers.Global_slot_since_genesis.t - -> raw_signature:string - -> expected_failure:string - -> unit Integration_test_lib.Malleable_error.t - - (** TODO: [get_account_permissions ~logger node account_id]*) - val get_account_permissions : + (** TODO: [get_pooled_zkapp_commands ~logger node ~pk] *) + val get_pooled_zkapp_commands : logger:Logger.t -> Inputs.Engine.Network.Node.t - -> Mina_base.Account_id.t - -> ( Mina_base.Permissions.t - Integration_test_lib.Malleable_error.Result_accumulator.t + -> pk:Signature_lib.Public_key.Compressed.t + -> ( string list Integration_test_lib.Malleable_error.Result_accumulator.t , Integration_test_lib.Malleable_error.Hard_fail.t ) result Async.Deferred.t - (** TODO: [get_account_update ~logger node account_id]*) - val get_account_update : - logger:Logger.t - -> Inputs.Engine.Network.Node.t - -> Mina_base.Account_id.t - -> ( Mina_base.Account_update.Update.t - Integration_test_lib.Malleable_error.Result_accumulator.t - , Integration_test_lib.Malleable_error.Hard_fail.t ) - result - Async.Deferred.t - - (** TODO: [compatible_item ... ~equal]*) + (** [compatible_item item1 item2 ~equal] compares items of different types + [item1] and [item2] for equality under [equal] *) val compatible_item : 'a Mina_base.Zkapp_basic.Set_or_keep.t -> 'b Mina_base.Zkapp_basic.Set_or_keep.t @@ -218,12 +245,14 @@ module Make : functor -> bool end - (** TODO: [check_replayer_logs ~logger ...]*) - val check_replayer_logs : - logger:Logger.t - -> string - -> ( unit Integration_test_lib.Malleable_error.Result_accumulator.t - , Integration_test_lib.Malleable_error.Hard_fail.t ) - result - Async.Deferred.t + module Archive_node : sig + (** [run_and_check_replayer ~logger network] runs and checks the archive node's replayer *) + val run_and_check_replayer : + logger:Logger.t + -> Inputs.Engine.Network.t + -> ( unit Integration_test_lib.Malleable_error.Result_accumulator.t + , Integration_test_lib.Malleable_error.Hard_fail.t ) + result + Async.Deferred.t + end end diff --git a/src/app/test_executive/verification_key_update.ml b/src/app/test_executive/verification_key_update.ml index d50d4123d0c..8ad22f98fe5 100644 --- a/src/app/test_executive/verification_key_update.ml +++ b/src/app/test_executive/verification_key_update.ml @@ -299,7 +299,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Send a zkApp to create a zkApp account" - (Zkapp.send ~logger whale1 zkapp_command_create_account) + (Zkapp_util.send ~logger whale1 zkapp_command_create_account) in let%bind () = section @@ -310,21 +310,21 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "Send zkApp to update verification key to v1 and then refers to v1 in \ the subsequent account update" - (Zkapp.send ~logger whale1 zkapp_command_update_vk1) + (Zkapp_util.send ~logger whale1 zkapp_command_update_vk1) in let%bind () = section "Send zkApp to update to a new verification key v2 and then refers to \ the old key v1" - (Zkapp.send_invalid ~logger whale1 zkapp_command_update_vk2_refers_vk1 - "Verification_failed" ) + (Zkapp_util.send_invalid ~logger whale1 + zkapp_command_update_vk2_refers_vk1 "Verification_failed" ) in let%bind () = section "Send zkApp to update to a new verification key v2 and then refers to \ that" - (Zkapp.send ~logger whale1 zkapp_command_update_vk2) + (Zkapp_util.send ~logger whale1 zkapp_command_update_vk2) in let%bind () = section diff --git a/src/app/test_executive/zkapps.ml b/src/app/test_executive/zkapps.ml index 2b089cb933d..104fcbfaf07 100644 --- a/src/app/test_executive/zkapps.ml +++ b/src/app/test_executive/zkapps.ml @@ -52,7 +52,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let send_zkapp ~logger node zkapp_command = incr transactions_sent ; - Zkapp.send ~logger node zkapp_command + Zkapp_util.send ~logger node zkapp_command let send_padding_transactions ~fee ~logger ~n nodes = let sender = List.nth_exn nodes 0 in @@ -98,7 +98,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in match expected_failure with | Some failure -> - Zkapp.send_invalid_payment ~logger ~sender_pub_key:sender_pk + Payment_util.send_invalid ~logger ~sender_pub_key:sender_pk ~receiver_pub_key:receiver_pk ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature ~expected_failure:failure node | None -> @@ -672,7 +672,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct [%log info] "Verifying permissions for account" ~metadata:[ ("account_id", Account_id.to_yojson account_id) ] ; let%bind ledger_permissions = - Zkapp.get_account_permissions ~logger node account_id + Account_util.get_permissions ~logger node account_id in if Permissions.equal ledger_permissions permissions_updated then ( [%log info] "Ledger, updated permissions are equal" ; @@ -692,7 +692,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkapp with an insufficient fee" - (Zkapp.send_invalid ~logger node zkapp_command_insufficient_fee + (Zkapp_util.send_invalid ~logger node zkapp_command_insufficient_fee "Insufficient fee" ) in (* Won't be accepted until the previous transactions are applied *) @@ -702,34 +702,34 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkapp with an invalid proof" - (Zkapp.send_invalid ~logger node zkapp_command_invalid_proof + (Zkapp_util.send_invalid ~logger node zkapp_command_invalid_proof "Verification_failed" ) in let%bind () = section_hard "Send a zkapp with an insufficient replace fee" - (Zkapp.send_invalid ~logger node zkapp_command_insufficient_replace_fee - "Insufficient_replace_fee" ) + (Zkapp_util.send_invalid ~logger node + zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid nonce" - (Zkapp.send_invalid ~logger node zkapp_command_invalid_nonce + (Zkapp_util.send_invalid ~logger node zkapp_command_invalid_nonce "Invalid_nonce" ) in let%bind () = section_hard "Send a zkApp transaction with insufficient_funds, fee too high" - (Zkapp.send_invalid ~logger node zkapp_command_insufficient_funds + (Zkapp_util.send_invalid ~logger node zkapp_command_insufficient_funds "Insufficient_funds" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid signature" - (Zkapp.send_invalid ~logger node zkapp_command_invalid_signature + (Zkapp_util.send_invalid ~logger node zkapp_command_invalid_signature "Verification_failed" ) in let%bind () = section_hard "Send a zkApp transaction with a nonexistent fee payer" - (Zkapp.send_invalid ~logger node zkapp_command_nonexistent_fee_payer - "Fee_payer_account_not_found" ) + (Zkapp_util.send_invalid ~logger node + zkapp_command_nonexistent_fee_payer "Fee_payer_account_not_found" ) in let%bind () = section_hard @@ -775,7 +775,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct [%log info] "Verifying updates for account" ~metadata:[ ("account_id", Account_id.to_yojson account_id) ] ; let%bind ledger_update = - Zkapp.get_account_update ~logger node account_id + Account_util.get_update ~logger node account_id in if compatible_updates ~ledger_update @@ -815,9 +815,5 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Event_router.cancel (event_router t) snark_work_event_subscription () ; Event_router.cancel (event_router t) snark_work_failure_subscription () ; section_hard "Running replayer" - (let%bind logs = - Network.Node.run_replayer ~logger - (List.hd_exn @@ (Network.archive_nodes network |> Core.Map.data)) - in - check_replayer_logs ~logger logs ) + (Archive_node.run_and_check_replayer ~logger network) end diff --git a/src/app/test_executive/zkapps_nonce_test.ml b/src/app/test_executive/zkapps_nonce_test.ml index 967b80ee7bc..c5d62380d1b 100644 --- a/src/app/test_executive/zkapps_nonce_test.ml +++ b/src/app/test_executive/zkapps_nonce_test.ml @@ -245,7 +245,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Send a zkapp commands with fee payer nonce increments and nonce \ preconditions" - (Zkapp.send_batch ~logger node + (Zkapp_util.send_batch ~logger node [ invalid_nonce_zkapp_cmd_from_fish1; valid_zkapp_cmd_from_fish1 ] ) in let%bind () = @@ -264,7 +264,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Send zkapp commands with account updates for fish1 that sets send \ permission to Proof and then tries to send funds " - (Zkapp.send_batch ~logger node + (Zkapp_util.send_batch ~logger node [ set_permission_zkapp_cmd_from_fish1 ; valid_fee_invalid_permission_zkapp_cmd_from_fish1 ; invalid_fee_invalid_permission_zkapp_cmd_from_fish1 @@ -332,10 +332,5 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Event_router.cancel (event_router t) snark_work_event_subscription () ; Event_router.cancel (event_router t) snark_work_failure_subscription () ; section_hard "Running replayer" - (let%bind logs = - Network.Node.run_replayer ~logger - ( List.hd_exn - @@ (Network.archive_nodes network |> Core.String.Map.data) ) - in - check_replayer_logs ~logger logs ) + (Archive_node.run_and_check_replayer ~logger network) end diff --git a/src/app/test_executive/zkapps_timing.ml b/src/app/test_executive/zkapps_timing.ml index 453fc0ba3a6..fd35b726e14 100644 --- a/src/app/test_executive/zkapps_timing.ml +++ b/src/app/test_executive/zkapps_timing.ml @@ -356,7 +356,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp to create a zkApp account with timing" - (Zkapp.send ~logger node zkapp_command_create_account_with_timing) + (Zkapp_util.send ~logger node zkapp_command_create_account_with_timing) in let%bind () = section @@ -367,7 +367,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 2nd zkApp account with timing" - (Zkapp.send ~logger node zkapp_command_create_second_account_with_timing) + (Zkapp_util.send ~logger node + zkapp_command_create_second_account_with_timing ) in let%bind () = section @@ -378,7 +379,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 3rd zkApp account with timing" - (Zkapp.send ~logger node zkapp_command_create_third_account_with_timing) + (Zkapp_util.send ~logger node + zkapp_command_create_third_account_with_timing ) in let%bind () = section @@ -390,10 +392,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify zkApp timing in ledger" (let%bind ledger_update = - Zkapp.get_account_update ~logger node timing_account_id + Account_util.get_update ~logger node timing_account_id in if - Zkapp.compatible_updates ~ledger_update + Zkapp_util.compatible_updates ~ledger_update ~requested_update:timing_update then ( [%log info] @@ -421,15 +423,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send invalid zkApp with zero vesting period in timing" - (Zkapp.send_invalid ~logger node zkapp_command_with_zero_vesting_period - "Zero vesting period" ) + (Zkapp_util.send_invalid ~logger node + zkapp_command_with_zero_vesting_period "Zero vesting period" ) in (* let%bind before_balance = get_account_balance ~logger node timing_account_id in *) let%bind () = section "Send a zkApp with transfer from timed account that succeeds" - (Zkapp.send ~logger node zkapp_command_transfer_from_timed_account) + (Zkapp_util.send ~logger node zkapp_command_transfer_from_timed_account) in let%bind () = section "Waiting for zkApp with transfer from timed account that succeeds" @@ -550,7 +552,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "Send a zkApp transfer from timed account with all its available funds \ at current global slot" - (Zkapp.send ~logger node zkapp_command_transfer_from_third_timed_account) + (Zkapp_util.send ~logger node + zkapp_command_transfer_from_third_timed_account ) in let%bind () = section @@ -604,7 +607,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct assert ( Currency.Amount.( < ) proposed_balance (Option.value_exn locked_balance |> Currency.Balance.to_amount) ) ; - Zkapp.send ~logger node + Zkapp_util.send ~logger node zkapp_command_invalid_transfer_from_timed_account ) in let%bind () = @@ -654,7 +657,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp with invalid timing update" - (Zkapp.send ~logger node zkapp_command_update_timing) + (Zkapp_util.send ~logger node zkapp_command_update_timing) in let%bind () = section "Wait for snapp with invalid timing update" @@ -663,10 +666,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify timing has not changed" (let%bind ledger_update = - Zkapp.get_account_update ~logger node timing_account_id + Account_util.get_update ~logger node timing_account_id in if - Zkapp.compatible_item ledger_update.timing timing_update.timing + Zkapp_util.compatible_item ledger_update.timing timing_update.timing ~equal:Mina_base.Account_update.Update.Timing_info.equal then ( [%log info] @@ -681,9 +684,5 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Error.of_string "Ledger update contains a timing update") ) ) in section_hard "Running replayer" - (let%bind logs = - Network.Node.run_replayer ~logger - (List.hd_exn @@ (Network.archive_nodes network |> Core.Map.data)) - in - check_replayer_logs ~logger logs ) + (Archive_node.run_and_check_replayer ~logger network) end