From 7f41ee443a8457bcf6315e94064801583ec1b022 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Thu, 15 Jun 2023 22:00:00 +0200 Subject: [PATCH 01/15] move graphql logic into integration_test_lib --- .../block_production_priority.ml | 14 +- .../test_executive/chain_reliability_test.ml | 5 +- src/app/test_executive/delegation_test.ml | 3 +- src/app/test_executive/payments_test.ml | 51 +- src/app/test_executive/test_common.ml | 10 +- .../graphql_polling_log_engine.ml | 6 +- .../kubernetes_network.ml | 634 +----------------- src/lib/integration_test_lib/dune | 10 +- src/lib/integration_test_lib/intf.ml | 274 ++++---- src/lib/integration_test_lib/test_config.ml | 4 +- 10 files changed, 218 insertions(+), 793 deletions(-) diff --git a/src/app/test_executive/block_production_priority.ml b/src/app/test_executive/block_production_priority.ml index 14e2e65fe29..104e17603de 100644 --- a/src/app/test_executive/block_production_priority.ml +++ b/src/app/test_executive/block_production_priority.ml @@ -135,8 +135,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Malleable_error.List.fold ~init:sender_priv_keys empty_bps ~f:(fun keys node -> let keys0, rest = List.split_n keys keys_per_sender in - Network.Node.must_send_test_payments ~repeat_count ~repeat_delay_ms - ~logger ~senders:keys0 ~receiver_pub_key ~amount ~fee node + Integration_test_lib.Graphql_requests.must_send_test_payments + ~repeat_count ~repeat_delay_ms ~logger ~senders:keys0 + ~receiver_pub_key ~amount ~fee + (Network.Node.get_ingress_uri node) >>| const rest ) >>| const () ) in @@ -150,8 +152,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "checked produced blocks" (let%bind blocks = - Network.Node.must_get_best_chain ~logger ~max_length:(2 * num_slots) - receiver + Integration_test_lib.Graphql_requests.must_get_best_chain ~logger + ~max_length:(2 * num_slots) + (Network.Node.get_ingress_uri receiver) in let%bind () = ok_if_true "not enough blocks" @@ -187,7 +190,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let get_metrics node = Async_kernel.Deferred.bind - (Network.Node.get_metrics ~logger node) + (Integration_test_lib.Graphql_requests.get_metrics ~logger + (Network.Node.get_ingress_uri node) ) ~f:Malleable_error.or_hard_error in let%bind () = diff --git a/src/app/test_executive/chain_reliability_test.ml b/src/app/test_executive/chain_reliability_test.ml index 3711ff5ec14..71d75c6bd1b 100644 --- a/src/app/test_executive/chain_reliability_test.ml +++ b/src/app/test_executive/chain_reliability_test.ml @@ -106,7 +106,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind (labeled_chains : (string * string list) list) = Malleable_error.List.map (Core.String.Map.data all_nodes) ~f:(fun node -> - let%map chain = Network.Node.must_get_best_chain ~logger node in + let%map chain = + Integration_test_lib.Graphql_requests.must_get_best_chain ~logger + (Node.get_ingress_uri node) + in (Node.id node, List.map ~f:(fun b -> b.state_hash) chain) ) in let (chains : string list list) = diff --git a/src/app/test_executive/delegation_test.ml b/src/app/test_executive/delegation_test.ml index fb0cb973fac..f5f383b47c7 100644 --- a/src/app/test_executive/delegation_test.ml +++ b/src/app/test_executive/delegation_test.ml @@ -55,7 +55,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct pub_key_of_node delegation_sender in let%bind { hash; _ } = - Network.Node.must_send_delegation ~logger delegation_sender + Integration_test_lib.Graphql_requests.must_send_delegation ~logger + (Network.Node.get_ingress_uri delegation_sender) ~sender_pub_key:delegation_sender_pub_key ~receiver_pub_key:delegation_receiver_pub_key ~fee in diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 3ce854cd997..686f95c0b41 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -78,7 +78,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct } let run network t = - let open Network in + (* let open Network in *) let open Malleable_error.Let_syntax in let logger = Logger.create () in let all_nodes = Network.all_nodes network in @@ -150,7 +150,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct } in let%bind { nonce = sender_current_nonce; _ } = - Network.Node.must_get_account_data ~logger untimed_node_b + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_b) ~public_key:sender_pub_key in let user_command_input = @@ -188,7 +189,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "send a single signed payment between 2 fish accounts" (let%bind { hash; _ } = - Network.Node.must_send_payment_with_raw_sig untimed_node_b ~logger + Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig + (Network.Node.get_ingress_uri untimed_node_b) + ~logger ~sender_pub_key: (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) ~receiver_pub_key: @@ -215,11 +218,13 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "check that the account balances are what we expect after the previous \ txn" (let%bind { total_balance = receiver_balance; _ } = - Network.Node.must_get_account_data ~logger untimed_node_b + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_b) ~public_key:receiver_pub_key in let%bind { total_balance = sender_balance; _ } = - Network.Node.must_get_account_data ~logger untimed_node_b + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_b) ~public_key:sender_pub_key in (* TODO, the intg test framework is ignoring test_constants.coinbase_amount for whatever reason, so hardcoding this until that is fixed *) @@ -278,7 +283,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct to conduct a replay attack. expecting a bad nonce" (let open Deferred.Let_syntax in match%bind - Network.Node.send_payment_with_raw_sig untimed_node_b ~logger + Integration_test_lib.Graphql_requests.send_payment_with_raw_sig + (Network.Node.get_ingress_uri untimed_node_b) + ~logger ~sender_pub_key: (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) ~receiver_pub_key: @@ -326,7 +333,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Invalid_signature" (let open Deferred.Let_syntax in match%bind - Network.Node.send_payment_with_raw_sig untimed_node_a ~logger + Integration_test_lib.Graphql_requests.send_payment_with_raw_sig + (Network.Node.get_ingress_uri untimed_node_a) + ~logger ~sender_pub_key: (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) ~receiver_pub_key: @@ -375,8 +384,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = timed_node_c in let%bind sender_pub_key = pub_key_of_node sender in let%bind { hash; _ } = - Network.Node.must_send_payment ~logger timed_node_c ~sender_pub_key - ~receiver_pub_key ~amount ~fee + Integration_test_lib.Graphql_requests.must_send_payment ~logger + (Network.Node.get_ingress_uri timed_node_c) + ~sender_pub_key ~receiver_pub_key ~amount ~fee in wait_for t (Wait_condition.signed_command_to_be_included_in_frontier @@ -390,7 +400,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = timed_node_c in let%bind sender_pub_key = pub_key_of_node sender in let%bind { total_balance = timed_node_c_total; _ } = - Network.Node.must_get_account_data ~logger timed_node_c + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri timed_node_c) ~public_key:sender_pub_key in [%log info] "timed_node_c total balance: %s" @@ -402,8 +413,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (* TODO: refactor this using new [expect] dsl when it's available *) let open Deferred.Let_syntax in match%bind - Node.send_payment ~logger sender ~sender_pub_key ~receiver_pub_key - ~amount ~fee + Integration_test_lib.Graphql_requests.send_payment ~logger + (Network.Node.get_ingress_uri sender) + ~sender_pub_key ~receiver_pub_key ~amount ~fee with | Ok _ -> Malleable_error.soft_error_string ~value:() @@ -460,13 +472,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "check account balances. snark-node-key1 should be greater than or \ equal to the snark fee" (let%bind { total_balance = key_1_balance_actual; _ } = - Network.Node.must_get_account_data ~logger untimed_node_b + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_b) ~public_key: ( snark_node_key1.keypair.public_key |> Signature_lib.Public_key.compress ) in let%bind { total_balance = key_2_balance_actual; _ } = - Network.Node.must_get_account_data ~logger untimed_node_a + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_a) ~public_key: ( snark_node_key2.keypair.public_key |> Signature_lib.Public_key.compress ) @@ -503,7 +517,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "change snark worker key from snark-node-key1 to snark-node-key2" (let%bind () = - Network.Node.must_set_snark_worker ~logger snark_coordinator + Integration_test_lib.Graphql_requests.must_set_snark_worker ~logger + (Network.Node.get_ingress_uri snark_coordinator) ~new_snark_pub_key: ( snark_node_key2.keypair.public_key |> Signature_lib.Public_key.compress ) @@ -532,13 +547,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "check account balances. snark-node-key2 should be greater than or \ equal to the snark fee" (let%bind { total_balance = key_1_balance_actual; _ } = - Network.Node.must_get_account_data ~logger untimed_node_b + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_b) ~public_key: ( snark_node_key1.keypair.public_key |> Signature_lib.Public_key.compress ) in let%bind { total_balance = key_2_balance_actual; _ } = - Network.Node.must_get_account_data ~logger untimed_node_a + Integration_test_lib.Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri untimed_node_a) ~public_key: ( snark_node_key2.keypair.public_key |> Signature_lib.Public_key.compress ) diff --git a/src/app/test_executive/test_common.ml b/src/app/test_executive/test_common.ml index b4b629ee5ee..00cecad5961 100644 --- a/src/app/test_executive/test_common.ml +++ b/src/app/test_executive/test_common.ml @@ -27,8 +27,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct else let%bind hash = let%map { hash; nonce; _ } = - Engine.Network.Node.must_send_payment ~logger ~sender_pub_key - ~receiver_pub_key ~amount ~fee node + Integration_test_lib.Graphql_requests.must_send_payment ~logger + ~sender_pub_key ~receiver_pub_key ~amount ~fee + (Engine.Network.Node.get_ingress_uri node) in [%log info] "sending multiple payments: payment #%d sent with hash of %s and \ @@ -128,7 +129,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let fetch_connectivity_data ~logger nodes = let open Malleable_error.Let_syntax in Malleable_error.List.map nodes ~f:(fun node -> - let%map response = Engine.Network.Node.must_get_peer_id ~logger node in + let%map response = + Integration_test_lib.Graphql_requests.must_get_peer_id ~logger + (Engine.Network.Node.get_ingress_uri node) + in (node, response) ) let assert_peers_completely_connected nodes_and_responses = diff --git a/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml b/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml index a779fc896fa..0a8aec3e561 100644 --- a/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml +++ b/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml @@ -62,7 +62,8 @@ let rec poll_get_filtered_log_entries_node ~logger ~event_writer if not (Pipe.is_closed event_writer) then ( let%bind () = after (Time.Span.of_ms 10000.0) in match%bind - Kubernetes_network.Node.get_filtered_log_entries ~last_log_index_seen node + Graphql_requests.get_filtered_log_entries ~last_log_index_seen + (Node.get_ingress_uri node) with | Ok log_entries -> Array.iter log_entries ~f:(fun log_entry -> @@ -94,7 +95,8 @@ let rec poll_start_filtered_log_node ~logger ~log_filter ~event_writer node = let open Deferred.Let_syntax in if not (Pipe.is_closed event_writer) then match%bind - Kubernetes_network.Node.start_filtered_log ~logger ~log_filter node + Graphql_requests.start_filtered_log ~logger ~log_filter + (Node.get_ingress_uri node) with | Ok () -> return (Ok ()) diff --git a/src/lib/integration_test_cloud_engine/kubernetes_network.ml b/src/lib/integration_test_cloud_engine/kubernetes_network.ml index 5aa05d6df5c..5655972cc5f 100644 --- a/src/lib/integration_test_cloud_engine/kubernetes_network.ml +++ b/src/lib/integration_test_cloud_engine/kubernetes_network.ml @@ -1,7 +1,6 @@ open Core_kernel open Async open Integration_test_lib -open Mina_base (* exclude from bisect_ppx to avoid type error on GraphQL modules *) [@@@coverage exclude_file] @@ -16,8 +15,6 @@ let postgres_url = Printf.sprintf "postgres://%s:%s@archive-1-postgresql:5432/archive" mina_archive_username mina_archive_pw -let node_password = "naughty blue worm" - type config = { testnet_name : string ; cluster : string @@ -50,6 +47,13 @@ module Node = struct let base_kube_args t = [ "--cluster"; t.cluster; "--namespace"; t.namespace ] + let get_ingress_uri node = + let host = + Printf.sprintf "%s.graphql.test.o1test.net" node.config.testnet_name + in + let path = Printf.sprintf "/%s/graphql" node.app_id in + Uri.make ~scheme:"http" ~host ~path ~port:80 () + let get_logs_in_container ?container_id { pod_ids; config; pod_info; _ } = let container_id = Option.value container_id ~default:pod_info.primary_container_id @@ -110,598 +114,12 @@ module Node = struct let open Malleable_error.Let_syntax in run_in_container ~exit_code:12 node ~cmd:[ "/stop.sh" ] >>| ignore - let logger_metadata node = + let logger_infra_metadata node = [ ("namespace", `String node.config.namespace) ; ("app_id", `String node.app_id) ; ("pod_id", `String (List.hd_exn node.pod_ids)) ] - module Scalars = Graphql_lib.Scalars - - module Graphql = struct - let ingress_uri node = - let host = - Printf.sprintf "%s.graphql.test.o1test.net" node.config.testnet_name - in - let path = Printf.sprintf "/%s/graphql" node.app_id in - Uri.make ~scheme:"http" ~host ~path ~port:80 () - - module Client = Graphql_lib.Client.Make (struct - let preprocess_variables_string = Fn.id - - let headers = String.Map.empty - end) - - (* graphql_ppx uses Stdlib symbols instead of Base *) - open Stdlib - module Encoders = Mina_graphql.Types.Input - - module Unlock_account = - [%graphql - ({| - mutation ($password: String!, $public_key: PublicKey!) @encoders(module: "Encoders"){ - unlockAccount(input: {password: $password, publicKey: $public_key }) { - account { - public_key: publicKey - } - } - } - |} - [@encoders Encoders] )] - - module Send_test_payments = - [%graphql - {| - mutation ($senders: [PrivateKey!]!, - $receiver: PublicKey!, - $amount: UInt64!, - $fee: UInt64!, - $repeat_count: UInt32!, - $repeat_delay_ms: UInt32!) @encoders(module: "Encoders"){ - sendTestPayments( - senders: $senders, receiver: $receiver, amount: $amount, fee: $fee, - repeat_count: $repeat_count, - repeat_delay_ms: $repeat_delay_ms) - } - |}] - - module Send_payment = - [%graphql - {| - mutation ($input: SendPaymentInput!)@encoders(module: "Encoders"){ - sendPayment(input: $input){ - payment { - id - nonce - hash - } - } - } - |}] - - module Send_payment_with_raw_sig = - [%graphql - {| - mutation ( - $input:SendPaymentInput!, - $rawSignature: String! - )@encoders(module: "Encoders") - { - sendPayment( - input:$input, - signature: {rawSignature: $rawSignature} - ) - { - payment { - id - nonce - hash - } - } - } - |}] - - module Send_delegation = - [%graphql - {| - mutation ($input: SendDelegationInput!) @encoders(module: "Encoders"){ - sendDelegation(input:$input){ - delegation { - id - nonce - hash - } - } - } - |}] - - module Set_snark_worker = - [%graphql - {| - mutation ($input: SetSnarkWorkerInput! ) @encoders(module: "Encoders"){ - setSnarkWorker(input:$input){ - lastSnarkWorker - } - } - |}] - - module Get_account_data = - [%graphql - {| - query ($public_key: PublicKey!) @encoders(module: "Encoders"){ - account(publicKey: $public_key) { - nonce - balance { - total @ppxCustom(module: "Scalars.Balance") - } - } - } - |}] - - module Query_peer_id = - [%graphql - {| - query { - daemonStatus { - addrsAndPorts { - peer { - peerId - } - } - peers { peerId } - - } - } - |}] - - module Best_chain = - [%graphql - {| - query ($max_length: Int) @encoders(module: "Encoders"){ - bestChain (maxLength: $max_length) { - stateHash - commandTransactionCount - creatorAccount { - publicKey @ppxCustom(module: "Graphql_lib.Scalars.JSON") - } - } - } - |}] - - module Query_metrics = - [%graphql - {| - query { - daemonStatus { - metrics { - blockProductionDelay - transactionPoolDiffReceived - transactionPoolDiffBroadcasted - transactionsAddedToPool - transactionPoolSize - } - } - } - |}] - - module StartFilteredLog = - [%graphql - {| - mutation ($filter: [String!]!) @encoders(module: "Encoders"){ - startFilteredLog(filter: $filter) - } - |}] - - module GetFilteredLogEntries = - [%graphql - {| - query ($offset: Int!) @encoders(module: "Encoders"){ - getFilteredLogEntries(offset: $offset) { - logMessages, - isCapturing, - } - } - |}] - end - - (* this function will repeatedly attempt to connect to graphql port times before giving up *) - let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) - ?(initial_delay_sec = 0.) ~logger ~node ~query_name query_obj = - let open Deferred.Let_syntax in - if not node.config.graphql_enabled then - Deferred.Or_error.error_string - "graphql is not enabled (hint: set `requires_graphql= true` in the \ - test config)" - else - let uri = Graphql.ingress_uri node in - let metadata = - [ ("query", `String query_name) - ; ("uri", `String (Uri.to_string uri)) - ; ("init_delay", `Float initial_delay_sec) - ] - in - [%log info] - "Attempting to send GraphQL request \"$query\" to \"$uri\" after \ - $init_delay sec" - ~metadata ; - let rec retry n = - if n <= 0 then ( - [%log error] - "GraphQL request \"$query\" to \"$uri\" failed too many times" - ~metadata ; - Deferred.Or_error.errorf - "GraphQL \"%s\" to \"%s\" request failed too many times" query_name - (Uri.to_string uri) ) - else - match%bind Graphql.Client.query query_obj uri with - | Ok result -> - [%log info] "GraphQL request \"$query\" to \"$uri\" succeeded" - ~metadata ; - Deferred.Or_error.return result - | Error (`Failed_request err_string) -> - [%log warn] - "GraphQL request \"$query\" to \"$uri\" failed: \"$error\" \ - ($num_tries attempts left)" - ~metadata: - ( metadata - @ [ ("error", `String err_string) - ; ("num_tries", `Int (n - 1)) - ] ) ; - let%bind () = after (Time.Span.of_sec retry_delay_sec) in - retry (n - 1) - | Error (`Graphql_error err_string) -> - [%log error] - "GraphQL request \"$query\" to \"$uri\" returned an error: \ - \"$error\" (this is a graphql error so not retrying)" - ~metadata:(metadata @ [ ("error", `String err_string) ]) ; - Deferred.Or_error.error_string err_string - in - let%bind () = after (Time.Span.of_sec initial_delay_sec) in - retry num_tries - - let get_peer_id ~logger t = - let open Deferred.Or_error.Let_syntax in - [%log info] "Getting node's peer_id, and the peer_ids of node's peers" - ~metadata:(logger_metadata t) ; - let query_obj = Graphql.Query_peer_id.(make @@ makeVariables ()) in - let%bind query_result_obj = - exec_graphql_request ~logger ~node:t ~query_name:"query_peer_id" query_obj - in - [%log info] "get_peer_id, finished exec_graphql_request" ; - let self_id_obj = query_result_obj.daemonStatus.addrsAndPorts.peer in - let%bind self_id = - match self_id_obj with - | None -> - Deferred.Or_error.error_string "Peer not found" - | Some peer -> - return peer.peerId - in - let peers = query_result_obj.daemonStatus.peers |> Array.to_list in - let peer_ids = List.map peers ~f:(fun peer -> peer.peerId) in - [%log info] "get_peer_id, result of graphql query (self_id,[peers]) (%s,%s)" - self_id - (String.concat ~sep:" " peer_ids) ; - return (self_id, peer_ids) - - let must_get_peer_id ~logger t = - get_peer_id ~logger t |> Deferred.bind ~f:Malleable_error.or_hard_error - - let get_best_chain ?max_length ~logger t = - let open Deferred.Or_error.Let_syntax in - let query = Graphql.Best_chain.(make @@ makeVariables ?max_length ()) in - let%bind result = - exec_graphql_request ~logger ~node:t ~query_name:"best_chain" query - in - match result.bestChain with - | None | Some [||] -> - Deferred.Or_error.error_string "failed to get best chains" - | Some chain -> - return - @@ List.map - ~f:(fun block -> - Intf. - { state_hash = block.stateHash - ; command_transaction_count = block.commandTransactionCount - ; creator_pk = - ( match block.creatorAccount.publicKey with - | `String pk -> - pk - | _ -> - "unknown" ) - } ) - (Array.to_list chain) - - let must_get_best_chain ?max_length ~logger t = - get_best_chain ?max_length ~logger t - |> Deferred.bind ~f:Malleable_error.or_hard_error - - type account_data = - { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } - - let get_account_data ~logger t ~public_key = - let open Deferred.Or_error.Let_syntax in - [%log info] "Getting account balance" - ~metadata: - ( ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key) - :: logger_metadata t ) ; - (* let pk = Mina_base.Account_id.public_key account_id in *) - (* let token = Mina_base.Account_id.token_id account_id in *) - let get_balance_obj = - Graphql.Get_account_data.( - make - @@ makeVariables ~public_key - (* ~token:(Graphql_lib.Encoders.token token) *) - ()) - in - let%bind balance_obj = - exec_graphql_request ~logger ~node:t ~query_name:"get_balance_graphql" - get_balance_obj - in - match balance_obj.account with - | None -> - Deferred.Or_error.errorf - !"Account with public_key %s not found" - (Signature_lib.Public_key.Compressed.to_string public_key) - | Some acc -> - return - { nonce = - acc.nonce - |> Option.value_exn ~message:"the nonce from get_balance is None" - |> Unsigned.UInt32.of_string - ; total_balance = acc.balance.total - } - - let must_get_account_data ~logger t ~public_key = - get_account_data ~logger t ~public_key - |> Deferred.bind ~f:Malleable_error.or_hard_error - - type signed_command_result = - { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } - - (* if we expect failure, might want retry_on_graphql_error to be false *) - let send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee = - [%log info] "Sending a payment" ~metadata:(logger_metadata t) ; - let open Deferred.Or_error.Let_syntax in - let sender_pk_str = - Signature_lib.Public_key.Compressed.to_string sender_pub_key - in - [%log info] "send_payment: unlocking account" - ~metadata:[ ("sender_pk", `String sender_pk_str) ] ; - let unlock_sender_account_graphql () = - let unlock_account_obj = - Graphql.Unlock_account.( - make - @@ makeVariables ~password:node_password ~public_key:sender_pub_key ()) - in - exec_graphql_request ~logger ~node:t ~initial_delay_sec:0. - ~query_name:"unlock_sender_account_graphql" unlock_account_obj - in - let%bind _ = unlock_sender_account_graphql () in - let send_payment_graphql () = - let input = - Mina_graphql.Types.Input.SendPaymentInput.make_input - ~from:sender_pub_key ~to_:receiver_pub_key ~amount ~fee () - in - let send_payment_obj = - Graphql.Send_payment.(make @@ makeVariables ~input ()) - in - exec_graphql_request ~logger ~node:t ~query_name:"send_payment_graphql" - send_payment_obj - in - let%map sent_payment_obj = send_payment_graphql () in - let return_obj = sent_payment_obj.sendPayment.payment in - let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce - } - in - [%log info] "Sent payment" - ~metadata: - [ ("user_command_id", `String res.id) - ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) - ] ; - res - - let must_send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee - = - send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee - |> Deferred.bind ~f:Malleable_error.or_hard_error - - let send_delegation ~logger t ~sender_pub_key ~receiver_pub_key ~fee = - [%log info] "Sending stake delegation" ~metadata:(logger_metadata t) ; - let open Deferred.Or_error.Let_syntax in - let sender_pk_str = - Signature_lib.Public_key.Compressed.to_string sender_pub_key - in - [%log info] "send_delegation: unlocking account" - ~metadata:[ ("sender_pk", `String sender_pk_str) ] ; - let unlock_sender_account_graphql () = - let unlock_account_obj = - Graphql.Unlock_account.( - make - @@ makeVariables ~password:"naughty blue worm" - ~public_key:sender_pub_key ()) - in - exec_graphql_request ~logger ~node:t - ~query_name:"unlock_sender_account_graphql" unlock_account_obj - in - let%bind _ = unlock_sender_account_graphql () in - let send_delegation_graphql () = - let input = - Mina_graphql.Types.Input.SendDelegationInput.make_input - ~from:sender_pub_key ~to_:receiver_pub_key ~fee () - in - let send_delegation_obj = - Graphql.Send_delegation.(make @@ makeVariables ~input ()) - in - exec_graphql_request ~logger ~node:t ~query_name:"send_delegation_graphql" - send_delegation_obj - in - let%map result_obj = send_delegation_graphql () in - let return_obj = result_obj.sendDelegation.delegation in - let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce - } - in - [%log info] "stake delegation sent" - ~metadata: - [ ("user_command_id", `String res.id) - ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) - ] ; - res - - let must_send_delegation ~logger t ~sender_pub_key ~receiver_pub_key ~fee = - send_delegation ~logger t ~sender_pub_key ~receiver_pub_key ~fee - |> Deferred.bind ~f:Malleable_error.or_hard_error - - let send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature = - [%log info] "Sending a payment with raw signature" - ~metadata:(logger_metadata t) ; - let open Deferred.Or_error.Let_syntax in - let send_payment_graphql () = - let open Graphql.Send_payment_with_raw_sig in - let input = - Mina_graphql.Types.Input.SendPaymentInput.make_input - ~from:sender_pub_key ~to_:receiver_pub_key ~amount ~token ~fee ~memo - ~nonce ~valid_until () - in - let variables = makeVariables ~input ~rawSignature:raw_signature () in - let send_payment_obj = make variables in - let variables_json_basic = - variablesToJson (serializeVariables variables) - in - (* An awkward conversion from Yojson.Basic to Yojson.Safe *) - let variables_json = - Yojson.Basic.to_string variables_json_basic |> Yojson.Safe.from_string - in - [%log info] "send_payment_obj with $variables " - ~metadata:[ ("variables", variables_json) ] ; - exec_graphql_request ~logger ~node:t - ~query_name:"Send_payment_with_raw_sig_graphql" send_payment_obj - in - let%map sent_payment_obj = send_payment_graphql () in - let return_obj = sent_payment_obj.sendPayment.payment in - let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce - } - in - [%log info] "Sent payment" - ~metadata: - [ ("user_command_id", `String res.id) - ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) - ] ; - res - - let must_send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature = - send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature - |> Deferred.bind ~f:Malleable_error.or_hard_error - - let send_test_payments ~repeat_count ~repeat_delay_ms ~logger t ~senders - ~receiver_pub_key ~amount ~fee = - [%log info] "Sending a series of test payments" - ~metadata:(logger_metadata t) ; - let open Deferred.Or_error.Let_syntax in - let send_payment_graphql () = - let send_payment_obj = - Graphql.Send_test_payments.( - make - @@ makeVariables ~senders ~receiver:receiver_pub_key - ~amount:(Currency.Amount.to_uint64 amount) - ~fee:(Currency.Fee.to_uint64 fee) - ~repeat_count ~repeat_delay_ms ()) - in - exec_graphql_request ~logger ~node:t ~query_name:"send_payment_graphql" - send_payment_obj - in - let%map _ = send_payment_graphql () in - [%log info] "Sent test payments" - - let must_send_test_payments ~repeat_count ~repeat_delay_ms ~logger t ~senders - ~receiver_pub_key ~amount ~fee = - send_test_payments ~repeat_count ~repeat_delay_ms ~logger t ~senders - ~receiver_pub_key ~amount ~fee - |> Deferred.bind ~f:Malleable_error.or_hard_error - - let set_snark_worker ~logger t ~new_snark_pub_key = - [%log info] "Changing snark worker key" ~metadata:(logger_metadata t) ; - let open Deferred.Or_error.Let_syntax in - let set_snark_worker_graphql () = - let input = Some new_snark_pub_key in - let set_snark_worker_obj = - Graphql.Set_snark_worker.(make @@ makeVariables ~input ()) - in - exec_graphql_request ~logger ~node:t - ~query_name:"set_snark_worker_graphql" set_snark_worker_obj - in - let%map result_obj = set_snark_worker_graphql () in - let returned_last_snark_worker_opt = - result_obj.setSnarkWorker.lastSnarkWorker - in - let last_snark_worker = - match returned_last_snark_worker_opt with - | None -> - "" - | Some last -> - last |> Account.Key.to_yojson |> Yojson.Safe.to_string - in - [%log info] "snark worker changed, lastSnarkWorker: %s" last_snark_worker - ~metadata:[ ("lastSnarkWorker", `String last_snark_worker) ] ; - () - - let must_set_snark_worker ~logger t ~new_snark_pub_key = - set_snark_worker ~logger t ~new_snark_pub_key - |> Deferred.bind ~f:Malleable_error.or_hard_error - - let start_filtered_log ~logger ~log_filter t = - let open Deferred.Let_syntax in - let query_obj = - Graphql.StartFilteredLog.(make @@ makeVariables ~filter:log_filter ()) - in - let%bind res = - exec_graphql_request ~logger:(Logger.null ()) ~retry_delay_sec:10.0 - ~node:t ~query_name:"StartFilteredLog" query_obj - in - match res with - | Ok query_result_obj -> - let had_already_started = query_result_obj.startFilteredLog in - if had_already_started then return (Ok ()) - else ( - [%log error] - "Attempted to start structured log collection on $node, but it had \ - already started" - ~metadata:[ ("node", `String t.app_id) ] ; - (* TODO: If this is common, figure out what to do *) - return (Ok ()) ) - | Error e -> - return (Error e) - - let get_filtered_log_entries ~last_log_index_seen t = - let open Deferred.Or_error.Let_syntax in - let query_obj = - Graphql.GetFilteredLogEntries.( - make @@ makeVariables ~offset:last_log_index_seen ()) - in - let%bind query_result_obj = - exec_graphql_request ~logger:(Logger.null ()) ~retry_delay_sec:10.0 - ~node:t ~query_name:"GetFilteredLogEntries" query_obj - in - let res = query_result_obj.getFilteredLogEntries in - if res.isCapturing then return res.logMessages - else - Deferred.Or_error.error_string - "Node is not currently capturing structured log messages" - let dump_archive_data ~logger (t : t) ~data_file = (* this function won't work if `t` doesn't happen to be an archive node *) if not t.pod_info.has_archive_container then @@ -859,42 +277,6 @@ module Node = struct Out_channel.output_string out_ch block ) ) in Malleable_error.return () - - let get_metrics ~logger t = - let open Deferred.Or_error.Let_syntax in - [%log info] "Getting node's metrics" ~metadata:(logger_metadata t) ; - let query_obj = Graphql.Query_metrics.make () in - let%bind query_result_obj = - exec_graphql_request ~logger ~node:t ~query_name:"query_metrics" query_obj - in - [%log info] "get_metrics, finished exec_graphql_request" ; - let block_production_delay = - Array.to_list - @@ query_result_obj.daemonStatus.metrics.blockProductionDelay - in - let metrics = query_result_obj.daemonStatus.metrics in - let transaction_pool_diff_received = metrics.transactionPoolDiffReceived in - let transaction_pool_diff_broadcasted = - metrics.transactionPoolDiffBroadcasted - in - let transactions_added_to_pool = metrics.transactionsAddedToPool in - let transaction_pool_size = metrics.transactionPoolSize in - [%log info] - "get_metrics, result of graphql query (block_production_delay; \ - tx_received; tx_broadcasted; txs_added_to_pool; tx_pool_size) (%s; %d; \ - %d; %d; %d)" - ( String.concat ~sep:", " - @@ List.map ~f:string_of_int block_production_delay ) - transaction_pool_diff_received transaction_pool_diff_broadcasted - transactions_added_to_pool transaction_pool_size ; - return - Intf. - { block_production_delay - ; transaction_pool_diff_broadcasted - ; transaction_pool_diff_received - ; transactions_added_to_pool - ; transaction_pool_size - } end module Workload_to_deploy = struct diff --git a/src/lib/integration_test_lib/dune b/src/lib/integration_test_lib/dune index ddc4fe0a280..d906118dcfc 100644 --- a/src/lib/integration_test_lib/dune +++ b/src/lib/integration_test_lib/dune @@ -3,13 +3,18 @@ (name integration_test_lib) (inline_tests) (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_base ppx_fields_conv ppx_coda ppx_version ppx_optcomp ppx_let ppx_inline_test ppx_custom_printf ppx_deriving.std ppx_sexp_conv ppx_compare ppx_assert lens.ppx_deriving ppx_pipebang)) + (preprocessor_deps ../../graphql-ppx-config.inc ../../../graphql_schema.json) + + (preprocess (pps ppx_base ppx_fields_conv ppx_coda ppx_version + ppx_let ppx_inline_test ppx_custom_printf ppx_deriving.std ppx_sexp_conv ppx_compare + ppx_assert lens.ppx_deriving ppx_pipebang graphql_ppx -- %{read-lines:../../graphql-ppx-config.inc})) (libraries ;; opam libraries result base.base_internalhash_types base.caml base + uri sexplib0 cmdliner async @@ -43,4 +48,7 @@ unsigned_extended transition_handler data_hash_lib + mina_graphql + graphql_lib + )) diff --git a/src/lib/integration_test_lib/intf.ml b/src/lib/integration_test_lib/intf.ml index 75c08ee5fa6..1bbfcd17367 100644 --- a/src/lib/integration_test_lib/intf.ml +++ b/src/lib/integration_test_lib/intf.ml @@ -48,139 +48,141 @@ module Engine = struct val stop : t -> unit Malleable_error.t - type signed_command_result = - { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } - - val send_payment : - logger:Logger.t - -> 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 - -> signed_command_result Deferred.Or_error.t - - val must_send_payment : - logger:Logger.t - -> 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 - -> signed_command_result Malleable_error.t - - val send_payment_with_raw_sig : - logger:Logger.t - -> 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:Mina_numbers.Account_nonce.t - -> memo:string - -> token:Token_id.t - -> valid_until:Mina_numbers.Global_slot.t - -> raw_signature:string - -> signed_command_result Deferred.Or_error.t - - val must_send_payment_with_raw_sig : - logger:Logger.t - -> 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:Mina_numbers.Account_nonce.t - -> memo:string - -> token:Token_id.t - -> valid_until:Mina_numbers.Global_slot.t - -> raw_signature:string - -> signed_command_result Malleable_error.t - - val send_delegation : - logger:Logger.t - -> t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> fee:Currency.Fee.t - -> signed_command_result Deferred.Or_error.t - - val must_send_delegation : - logger:Logger.t - -> t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> fee:Currency.Fee.t - -> signed_command_result Malleable_error.t - - val set_snark_worker : - logger:Logger.t - -> t - -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t - -> unit Deferred.Or_error.t - - val must_set_snark_worker : - logger:Logger.t - -> t - -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t - -> unit Malleable_error.t - - val must_send_test_payments : - repeat_count:Unsigned.uint32 - -> repeat_delay_ms:Unsigned.uint32 - -> logger:Logger.t - -> t - -> senders:Signature_lib.Private_key.t list - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> amount:Currency.Amount.t - -> fee:Currency.Fee.t - -> unit Malleable_error.t - - type account_data = - { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } - - val get_account_data : - logger:Logger.t - -> t - -> public_key:Signature_lib.Public_key.Compressed.t - -> account_data Async_kernel.Deferred.Or_error.t - - val must_get_account_data : - logger:Logger.t - -> t - -> public_key:Signature_lib.Public_key.Compressed.t - -> account_data Malleable_error.t - - val get_filtered_log_entries : - last_log_index_seen:int - -> t - -> string array Async_kernel.Deferred.Or_error.t - - val start_filtered_log : - logger:Logger.t - -> log_filter:string list - -> t - -> unit Async_kernel.Deferred.Or_error.t - - val get_peer_id : - logger:Logger.t - -> t - -> (string * string list) Async_kernel.Deferred.Or_error.t - - val must_get_peer_id : - logger:Logger.t -> t -> (string * string list) Malleable_error.t - - val get_best_chain : - ?max_length:int - -> logger:Logger.t - -> t - -> best_chain_block list Async_kernel.Deferred.Or_error.t - - val must_get_best_chain : - ?max_length:int - -> logger:Logger.t - -> t - -> best_chain_block list Malleable_error.t + val get_ingress_uri : t -> Uri.t + (* + type signed_command_result = + { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } + + val send_payment : + logger:Logger.t + -> 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 + -> signed_command_result Deferred.Or_error.t + + val must_send_payment : + logger:Logger.t + -> 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 + -> signed_command_result Malleable_error.t + + val send_payment_with_raw_sig : + logger:Logger.t + -> 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:Mina_numbers.Account_nonce.t + -> memo:string + -> token:Token_id.t + -> valid_until:Mina_numbers.Global_slot.t + -> raw_signature:string + -> signed_command_result Deferred.Or_error.t + + val must_send_payment_with_raw_sig : + logger:Logger.t + -> 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:Mina_numbers.Account_nonce.t + -> memo:string + -> token:Token_id.t + -> valid_until:Mina_numbers.Global_slot.t + -> raw_signature:string + -> signed_command_result Malleable_error.t + + val send_delegation : + logger:Logger.t + -> t + -> sender_pub_key:Signature_lib.Public_key.Compressed.t + -> receiver_pub_key:Signature_lib.Public_key.Compressed.t + -> fee:Currency.Fee.t + -> signed_command_result Deferred.Or_error.t + + val must_send_delegation : + logger:Logger.t + -> t + -> sender_pub_key:Signature_lib.Public_key.Compressed.t + -> receiver_pub_key:Signature_lib.Public_key.Compressed.t + -> fee:Currency.Fee.t + -> signed_command_result Malleable_error.t + + val set_snark_worker : + logger:Logger.t + -> t + -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t + -> unit Deferred.Or_error.t + + val must_set_snark_worker : + logger:Logger.t + -> t + -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t + -> unit Malleable_error.t + + val must_send_test_payments : + repeat_count:Unsigned.uint32 + -> repeat_delay_ms:Unsigned.uint32 + -> logger:Logger.t + -> t + -> senders:Signature_lib.Private_key.t list + -> receiver_pub_key:Signature_lib.Public_key.Compressed.t + -> amount:Currency.Amount.t + -> fee:Currency.Fee.t + -> unit Malleable_error.t + + type account_data = + { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } + + val get_account_data : + logger:Logger.t + -> t + -> public_key:Signature_lib.Public_key.Compressed.t + -> account_data Async_kernel.Deferred.Or_error.t + + val must_get_account_data : + logger:Logger.t + -> t + -> public_key:Signature_lib.Public_key.Compressed.t + -> account_data Malleable_error.t + + val get_filtered_log_entries : + last_log_index_seen:int + -> t + -> string array Async_kernel.Deferred.Or_error.t + + val start_filtered_log : + logger:Logger.t + -> log_filter:string list + -> t + -> unit Async_kernel.Deferred.Or_error.t + + val get_peer_id : + logger:Logger.t + -> t + -> (string * string list) Async_kernel.Deferred.Or_error.t + + val must_get_peer_id : + logger:Logger.t -> t -> (string * string list) Malleable_error.t + + val get_best_chain : + ?max_length:int + -> logger:Logger.t + -> t + -> best_chain_block list Async_kernel.Deferred.Or_error.t + + val must_get_best_chain : + ?max_length:int + -> logger:Logger.t + -> t + -> best_chain_block list Malleable_error.t *) val dump_archive_data : logger:Logger.t -> t -> data_file:string -> unit Malleable_error.t @@ -192,9 +194,9 @@ module Engine = struct val dump_precomputed_blocks : logger:Logger.t -> t -> unit Malleable_error.t - - val get_metrics : - logger:Logger.t -> t -> metrics_t Async_kernel.Deferred.Or_error.t + (* + val get_metrics : + logger:Logger.t -> t -> metrics_t Async_kernel.Deferred.Or_error.t *) end type t diff --git a/src/lib/integration_test_lib/test_config.ml b/src/lib/integration_test_lib/test_config.ml index c9450aa8e4a..a05a9ee5e11 100644 --- a/src/lib/integration_test_lib/test_config.ml +++ b/src/lib/integration_test_lib/test_config.ml @@ -67,7 +67,9 @@ let proof_config_default : Runtime_config.Proof_keys.t = } let default = - { requires_graphql = false + { requires_graphql = + true + (* require_graphql maybe should just be phased out, because it always needs to be enable. Now with the graphql polling engine, everything will definitely fail if graphql is not enabled. But even before that, most tests relied on some sort of graphql interaction *) ; genesis_ledger = [] ; block_producers = [] ; snark_coordinator = None From cc50d9d72e54660ca6147ccf5cfad72b76d15888 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Fri, 16 Jun 2023 01:08:19 +0200 Subject: [PATCH 02/15] for some reason it not compiling in ci but is locally --- .../graphql_polling_log_engine.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml b/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml index 0a8aec3e561..af6b6eb712d 100644 --- a/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml +++ b/src/lib/integration_test_cloud_engine/graphql_polling_log_engine.ml @@ -62,7 +62,8 @@ let rec poll_get_filtered_log_entries_node ~logger ~event_writer if not (Pipe.is_closed event_writer) then ( let%bind () = after (Time.Span.of_ms 10000.0) in match%bind - Graphql_requests.get_filtered_log_entries ~last_log_index_seen + Integration_test_lib.Graphql_requests.get_filtered_log_entries + ~last_log_index_seen (Node.get_ingress_uri node) with | Ok log_entries -> @@ -95,7 +96,8 @@ let rec poll_start_filtered_log_node ~logger ~log_filter ~event_writer node = let open Deferred.Let_syntax in if not (Pipe.is_closed event_writer) then match%bind - Graphql_requests.start_filtered_log ~logger ~log_filter + Integration_test_lib.Graphql_requests.start_filtered_log ~logger + ~log_filter (Node.get_ingress_uri node) with | Ok () -> From ef02f73664597ca65d59195e1ef04b6bdf8fb9be Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Fri, 16 Jun 2023 12:59:16 +0200 Subject: [PATCH 03/15] forgot to git add the most important file lol --- .../integration_test_lib/graphql_requests.ml | 631 ++++++++++++++++++ 1 file changed, 631 insertions(+) create mode 100644 src/lib/integration_test_lib/graphql_requests.ml diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml new file mode 100644 index 00000000000..48e619d4460 --- /dev/null +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -0,0 +1,631 @@ +open Core_kernel +open Async +open Mina_base + +let node_password = "naughty blue worm" + +module Graphql = struct + module Client = Graphql_lib.Client.Make (struct + let preprocess_variables_string = Fn.id + + let headers = String.Map.empty + end) + + (* graphql_ppx uses Stdlib symbols instead of Base *) + open Stdlib + module Encoders = Mina_graphql.Types.Input + module Scalars = Graphql_lib.Scalars + + module Unlock_account = + [%graphql + ({| + mutation ($password: String!, $public_key: PublicKey!) @encoders(module: "Encoders"){ + unlockAccount(input: {password: $password, publicKey: $public_key }) { + account { + public_key: publicKey + } + } + } + |} + [@encoders Encoders] )] + + module Send_test_payments = + [%graphql + {| + mutation ($senders: [PrivateKey!]!, + $receiver: PublicKey!, + $amount: UInt64!, + $fee: UInt64!, + $repeat_count: UInt32!, + $repeat_delay_ms: UInt32!) @encoders(module: "Encoders"){ + sendTestPayments( + senders: $senders, receiver: $receiver, amount: $amount, fee: $fee, + repeat_count: $repeat_count, + repeat_delay_ms: $repeat_delay_ms) + } + |}] + + module Send_payment = + [%graphql + {| + mutation ($input: SendPaymentInput!)@encoders(module: "Encoders"){ + sendPayment(input: $input){ + payment { + id + nonce + hash + } + } + } + |}] + + module Send_payment_with_raw_sig = + [%graphql + {| + mutation ( + $input:SendPaymentInput!, + $rawSignature: String! + )@encoders(module: "Encoders") + { + sendPayment( + input:$input, + signature: {rawSignature: $rawSignature} + ) + { + payment { + id + nonce + hash + } + } + } + |}] + + module Send_delegation = + [%graphql + {| + mutation ($input: SendDelegationInput!) @encoders(module: "Encoders"){ + sendDelegation(input:$input){ + delegation { + id + nonce + hash + } + } + } + |}] + + module Set_snark_worker = + [%graphql + {| + mutation ($input: SetSnarkWorkerInput! ) @encoders(module: "Encoders"){ + setSnarkWorker(input:$input){ + lastSnarkWorker + } + } + |}] + + module Get_account_data = + [%graphql + {| + query ($public_key: PublicKey!) @encoders(module: "Encoders"){ + account(publicKey: $public_key) { + nonce + balance { + total @ppxCustom(module: "Scalars.Balance") + } + } + } + |}] + + module Query_peer_id = + [%graphql + {| + query { + daemonStatus { + addrsAndPorts { + peer { + peerId + } + } + peers { peerId } + + } + } + |}] + + module Best_chain = + [%graphql + {| + query ($max_length: Int) @encoders(module: "Encoders"){ + bestChain (maxLength: $max_length) { + stateHash + commandTransactionCount + creatorAccount { + publicKey @ppxCustom(module: "Graphql_lib.Scalars.JSON") + } + } + } + |}] + + module Query_metrics = + [%graphql + {| + query { + daemonStatus { + metrics { + blockProductionDelay + transactionPoolDiffReceived + transactionPoolDiffBroadcasted + transactionsAddedToPool + transactionPoolSize + } + } + } + |}] + + module StartFilteredLog = + [%graphql + {| + mutation ($filter: [String!]!) @encoders(module: "Encoders"){ + startFilteredLog(filter: $filter) + } + |}] + + module GetFilteredLogEntries = + [%graphql + {| + query ($offset: Int!) @encoders(module: "Encoders"){ + getFilteredLogEntries(offset: $offset) { + logMessages, + isCapturing, + } + } + |}] +end + +(* this function will repeatedly attempt to connect to graphql port times before giving up *) +let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) + ?(initial_delay_sec = 0.) ~logger ~node_uri ~query_name query_obj = + let open Deferred.Let_syntax in + let metadata = + [ ("query", `String query_name) + ; ("uri", `String (Uri.to_string node_uri)) + ; ("init_delay", `Float initial_delay_sec) + ] + in + [%log info] + "Attempting to send GraphQL request \"$query\" to \"$uri\" after \ + $init_delay sec" + ~metadata ; + let rec retry n = + if n <= 0 then ( + [%log error] + "GraphQL request \"$query\" to \"$uri\" failed too many times" ~metadata ; + Deferred.Or_error.errorf + "GraphQL \"%s\" to \"%s\" request failed too many times" query_name + (Uri.to_string node_uri) ) + else + match%bind Graphql.Client.query query_obj node_uri with + | Ok result -> + [%log info] "GraphQL request \"$query\" to \"$uri\" succeeded" + ~metadata ; + Deferred.Or_error.return result + | Error (`Failed_request err_string) -> + [%log warn] + "GraphQL request \"$query\" to \"$uri\" failed: \"$error\" \ + ($num_tries attempts left)" + ~metadata: + ( metadata + @ [ ("error", `String err_string); ("num_tries", `Int (n - 1)) ] + ) ; + let%bind () = after (Time.Span.of_sec retry_delay_sec) in + retry (n - 1) + | Error (`Graphql_error err_string) -> + [%log error] + "GraphQL request \"$query\" to \"$uri\" returned an error: \ + \"$error\" (this is a graphql error so not retrying)" + ~metadata:(metadata @ [ ("error", `String err_string) ]) ; + Deferred.Or_error.error_string err_string + in + let%bind () = after (Time.Span.of_sec initial_delay_sec) in + retry num_tries + +let get_peer_id ~logger node_uri = + let open Deferred.Or_error.Let_syntax in + [%log info] "Getting node's peer_id, and the peer_ids of node's peers" + ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + let query_obj = Graphql.Query_peer_id.(make @@ makeVariables ()) in + let%bind query_result_obj = + exec_graphql_request ~logger ~node_uri ~query_name:"query_peer_id" query_obj + in + [%log info] "get_peer_id, finished exec_graphql_request" ; + let self_id_obj = query_result_obj.daemonStatus.addrsAndPorts.peer in + let%bind self_id = + match self_id_obj with + | None -> + Deferred.Or_error.error_string "Peer not found" + | Some peer -> + return peer.peerId + in + let peers = query_result_obj.daemonStatus.peers |> Array.to_list in + let peer_ids = List.map peers ~f:(fun peer -> peer.peerId) in + [%log info] "get_peer_id, result of graphql query (self_id,[peers]) (%s,%s)" + self_id + (String.concat ~sep:" " peer_ids) ; + return (self_id, peer_ids) + +let must_get_peer_id ~logger node_uri = + get_peer_id ~logger node_uri |> Deferred.bind ~f:Malleable_error.or_hard_error + +let get_best_chain ?max_length ~logger node_uri = + let open Deferred.Or_error.Let_syntax in + let query = Graphql.Best_chain.(make @@ makeVariables ?max_length ()) in + let%bind result = + exec_graphql_request ~logger ~node_uri ~query_name:"best_chain" query + in + match result.bestChain with + | None | Some [||] -> + Deferred.Or_error.error_string "failed to get best chains" + | Some chain -> + return + @@ List.map + ~f:(fun block -> + Intf. + { state_hash = block.stateHash + ; command_transaction_count = block.commandTransactionCount + ; creator_pk = + ( match block.creatorAccount.publicKey with + | `String pk -> + pk + | _ -> + "unknown" ) + } ) + (Array.to_list chain) + +let must_get_best_chain ?max_length ~logger node_uri = + get_best_chain ?max_length ~logger node_uri + |> Deferred.bind ~f:Malleable_error.or_hard_error + +type account_data = + { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } + +let get_account_data ~logger node_uri ~public_key = + let open Deferred.Or_error.Let_syntax in + [%log info] "Getting account balance" + ~metadata: + [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key) + ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ] ; + (* let pk = Mina_base.Account_id.public_key account_id in *) + (* let token = Mina_base.Account_id.token_id account_id in *) + let get_balance_obj = + Graphql.Get_account_data.( + make + @@ makeVariables ~public_key + (* ~token:(Graphql_lib.Encoders.token token) *) + ()) + in + let%bind balance_obj = + exec_graphql_request ~logger ~node_uri ~query_name:"get_balance_graphql" + get_balance_obj + in + match balance_obj.account with + | None -> + Deferred.Or_error.errorf + !"Account with public_key %s not found" + (Signature_lib.Public_key.Compressed.to_string public_key) + | Some acc -> + return + { nonce = + acc.nonce + |> Option.value_exn ~message:"the nonce from get_balance is None" + |> Unsigned.UInt32.of_string + ; total_balance = acc.balance.total + } + +let must_get_account_data ~logger node_uri ~public_key = + get_account_data ~logger node_uri ~public_key + |> Deferred.bind ~f:Malleable_error.or_hard_error + +type signed_command_result = + { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } + +(* if we expect failure, might want retry_on_graphql_error to be false *) +let send_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee + = + [%log info] "Sending a payment" + ~metadata: + [ ( "sender_pub_key" + , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) + ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ] ; + let open Deferred.Or_error.Let_syntax in + let sender_pk_str = + Signature_lib.Public_key.Compressed.to_string sender_pub_key + in + [%log info] "send_payment: unlocking account" + ~metadata:[ ("sender_pk", `String sender_pk_str) ] ; + let unlock_sender_account_graphql () = + let unlock_account_obj = + Graphql.Unlock_account.( + make + @@ makeVariables ~password:node_password ~public_key:sender_pub_key ()) + in + exec_graphql_request ~logger ~node_uri ~initial_delay_sec:0. + ~query_name:"unlock_sender_account_graphql" unlock_account_obj + in + let%bind _ = unlock_sender_account_graphql () in + let send_payment_graphql () = + let input = + Mina_graphql.Types.Input.SendPaymentInput.make_input ~from:sender_pub_key + ~to_:receiver_pub_key ~amount ~fee () + in + let send_payment_obj = + Graphql.Send_payment.(make @@ makeVariables ~input ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"send_payment_graphql" + send_payment_obj + in + let%map sent_payment_obj = send_payment_graphql () in + let return_obj = sent_payment_obj.sendPayment.payment in + let res = + { id = return_obj.id + ; hash = Transaction_hash.of_base58_check_exn return_obj.hash + ; nonce = Unsigned.UInt32.of_int return_obj.nonce + } + in + [%log info] "Sent payment" + ~metadata: + [ ("user_command_id", `String res.id) + ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) + ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ] ; + res + +let must_send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee = + send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee + |> Deferred.bind ~f:Malleable_error.or_hard_error + +let send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee = + [%log info] "Sending stake delegation" + ~metadata: + [ ( "sender_pub_key" + , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) + ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ] ; + let open Deferred.Or_error.Let_syntax in + let sender_pk_str = + Signature_lib.Public_key.Compressed.to_string sender_pub_key + in + [%log info] "send_delegation: unlocking account" + ~metadata:[ ("sender_pk", `String sender_pk_str) ] ; + let unlock_sender_account_graphql () = + let unlock_account_obj = + Graphql.Unlock_account.( + make + @@ makeVariables ~password:"naughty blue worm" + ~public_key:sender_pub_key ()) + in + exec_graphql_request ~logger ~node_uri + ~query_name:"unlock_sender_account_graphql" unlock_account_obj + in + let%bind _ = unlock_sender_account_graphql () in + let send_delegation_graphql () = + let input = + Mina_graphql.Types.Input.SendDelegationInput.make_input + ~from:sender_pub_key ~to_:receiver_pub_key ~fee () + in + let send_delegation_obj = + Graphql.Send_delegation.(make @@ makeVariables ~input ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"send_delegation_graphql" + send_delegation_obj + in + let%map result_obj = send_delegation_graphql () in + let return_obj = result_obj.sendDelegation.delegation in + let res = + { id = return_obj.id + ; hash = Transaction_hash.of_base58_check_exn return_obj.hash + ; nonce = Unsigned.UInt32.of_int return_obj.nonce + } + in + [%log info] "stake delegation sent" + ~metadata: + [ ("user_command_id", `String res.id) + ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) + ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ] ; + res + +let must_send_delegation ~logger node_uri ~sender_pub_key + ~(receiver_pub_key : Account.key) ~fee = + send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee + |> Deferred.bind ~f:Malleable_error.or_hard_error + +let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key + ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature = + [%log info] "Sending a payment with raw signature" + ~metadata: + [ ( "sender_pub_key" + , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) + ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ] ; + let open Deferred.Or_error.Let_syntax in + let send_payment_graphql () = + let open Graphql.Send_payment_with_raw_sig in + let input = + Mina_graphql.Types.Input.SendPaymentInput.make_input ~from:sender_pub_key + ~to_:receiver_pub_key ~amount ~token ~fee ~memo ~nonce ~valid_until () + in + let variables = makeVariables ~input ~rawSignature:raw_signature () in + let send_payment_obj = make variables in + let variables_json_basic = variablesToJson (serializeVariables variables) in + (* An awkward conversion from Yojson.Basic to Yojson.Safe *) + let variables_json = + Yojson.Basic.to_string variables_json_basic |> Yojson.Safe.from_string + in + [%log info] "send_payment_obj with $variables " + ~metadata:[ ("variables", variables_json) ] ; + exec_graphql_request ~logger ~node_uri + ~query_name:"Send_payment_with_raw_sig_graphql" send_payment_obj + in + let%map sent_payment_obj = send_payment_graphql () in + let return_obj = sent_payment_obj.sendPayment.payment in + let res = + { id = return_obj.id + ; hash = Transaction_hash.of_base58_check_exn return_obj.hash + ; nonce = Unsigned.UInt32.of_int return_obj.nonce + } + in + [%log info] "Sent payment" + ~metadata: + [ ("user_command_id", `String res.id) + ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) + ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ] ; + res + +let must_send_payment_with_raw_sig ~logger node_uri ~sender_pub_key + ~receiver_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until + ~raw_signature = + send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key + ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature + |> Deferred.bind ~f:Malleable_error.or_hard_error + +let send_test_payments ~(repeat_count : Unsigned.UInt32.t) + ~(repeat_delay_ms : Unsigned.UInt32.t) ~logger node_uri + ~(senders : Import.Private_key.t list) ~(receiver_pub_key : Account.key) + ~amount ~fee = + [%log info] "Sending a series of test payments" + ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + let open Deferred.Or_error.Let_syntax in + let send_payment_graphql () = + let send_payment_obj = + Graphql.Send_test_payments.( + make + @@ makeVariables ~senders ~receiver:receiver_pub_key + ~amount:(Currency.Amount.to_uint64 amount) + ~fee:(Currency.Fee.to_uint64 fee) + ~repeat_count ~repeat_delay_ms ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"send_payment_graphql" + send_payment_obj + in + let%map _ = send_payment_graphql () in + [%log info] "Sent test payments" + +let must_send_test_payments ~repeat_count ~repeat_delay_ms ~logger t ~senders + ~receiver_pub_key ~amount ~fee = + send_test_payments ~repeat_count ~repeat_delay_ms ~logger t ~senders + ~receiver_pub_key ~amount ~fee + |> Deferred.bind ~f:Malleable_error.or_hard_error + +let set_snark_worker ~logger node_uri ~new_snark_pub_key = + [%log info] "Changing snark worker key" + ~metadata: + [ ( "new_snark_pub_key" + , Signature_lib.Public_key.Compressed.to_yojson new_snark_pub_key ) + ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ] ; + let open Deferred.Or_error.Let_syntax in + let set_snark_worker_graphql () = + let input = Some new_snark_pub_key in + let set_snark_worker_obj = + Graphql.Set_snark_worker.(make @@ makeVariables ~input ()) + in + exec_graphql_request ~logger ~node_uri + ~query_name:"set_snark_worker_graphql" set_snark_worker_obj + in + let%map result_obj = set_snark_worker_graphql () in + let returned_last_snark_worker_opt = + result_obj.setSnarkWorker.lastSnarkWorker + in + let last_snark_worker = + match returned_last_snark_worker_opt with + | None -> + "" + | Some last -> + last |> Account.Key.to_yojson |> Yojson.Safe.to_string + in + [%log info] "snark worker changed, lastSnarkWorker: %s" last_snark_worker + ~metadata:[ ("lastSnarkWorker", `String last_snark_worker) ] ; + () + +let must_set_snark_worker ~logger t ~new_snark_pub_key = + set_snark_worker ~logger t ~new_snark_pub_key + |> Deferred.bind ~f:Malleable_error.or_hard_error + +let get_metrics ~logger node_uri = + let open Deferred.Or_error.Let_syntax in + [%log info] "Getting node's metrics" + ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + let query_obj = Graphql.Query_metrics.make () in + let%bind query_result_obj = + exec_graphql_request ~logger ~node_uri ~query_name:"query_metrics" query_obj + in + [%log info] "get_metrics, finished exec_graphql_request" ; + let block_production_delay = + Array.to_list @@ query_result_obj.daemonStatus.metrics.blockProductionDelay + in + let metrics = query_result_obj.daemonStatus.metrics in + let transaction_pool_diff_received = metrics.transactionPoolDiffReceived in + let transaction_pool_diff_broadcasted = + metrics.transactionPoolDiffBroadcasted + in + let transactions_added_to_pool = metrics.transactionsAddedToPool in + let transaction_pool_size = metrics.transactionPoolSize in + [%log info] + "get_metrics, result of graphql query (block_production_delay; \ + tx_received; tx_broadcasted; txs_added_to_pool; tx_pool_size) (%s; %d; \ + %d; %d; %d)" + (String.concat ~sep:", " @@ List.map ~f:string_of_int block_production_delay) + transaction_pool_diff_received transaction_pool_diff_broadcasted + transactions_added_to_pool transaction_pool_size ; + return + Intf. + { block_production_delay + ; transaction_pool_diff_broadcasted + ; transaction_pool_diff_received + ; transactions_added_to_pool + ; transaction_pool_size + } + +let start_filtered_log ~logger ~log_filter node_uri = + let open Deferred.Let_syntax in + let query_obj = + Graphql.StartFilteredLog.(make @@ makeVariables ~filter:log_filter ()) + in + let%bind res = + exec_graphql_request ~logger:(Logger.null ()) ~retry_delay_sec:10.0 + ~node_uri ~query_name:"StartFilteredLog" query_obj + in + match res with + | Ok query_result_obj -> + let had_already_started = query_result_obj.startFilteredLog in + if had_already_started then return (Ok ()) + else ( + [%log error] + "Attempted to start structured log collection on $node, but it had \ + already started" + ~metadata:[ ("node", `String (Uri.to_string node_uri)) ] ; + (* TODO: If this is common, figure out what to do *) + return (Ok ()) ) + | Error e -> + return (Error e) + +let get_filtered_log_entries ~last_log_index_seen node_uri = + let open Deferred.Or_error.Let_syntax in + let query_obj = + Graphql.GetFilteredLogEntries.( + make @@ makeVariables ~offset:last_log_index_seen ()) + in + let%bind query_result_obj = + exec_graphql_request ~logger:(Logger.null ()) ~retry_delay_sec:10.0 + ~node_uri ~query_name:"GetFilteredLogEntries" query_obj + in + let res = query_result_obj.getFilteredLogEntries in + if res.isCapturing then return res.logMessages + else + Deferred.Or_error.error_string + "Node is not currently capturing structured log messages" From 268e943cc02b31728f2f3b4161bb03cc318b62a3 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Fri, 16 Jun 2023 19:47:43 +0200 Subject: [PATCH 04/15] fix yojson runtime error --- src/lib/integration_test_lib/graphql_requests.ml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index 48e619d4460..c0401992f3a 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -234,7 +234,7 @@ let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) let get_peer_id ~logger node_uri = let open Deferred.Or_error.Let_syntax in [%log info] "Getting node's peer_id, and the peer_ids of node's peers" - ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + ~metadata:[ ("node_uri", `String (Uri.to_string node_uri)) ] ; let query_obj = Graphql.Query_peer_id.(make @@ makeVariables ()) in let%bind query_result_obj = exec_graphql_request ~logger ~node_uri ~query_name:"query_peer_id" query_obj @@ -295,7 +295,7 @@ let get_account_data ~logger node_uri ~public_key = [%log info] "Getting account balance" ~metadata: [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key) - ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ; ("node_uri", `String (Uri.to_string node_uri)) ] ; (* let pk = Mina_base.Account_id.public_key account_id in *) (* let token = Mina_base.Account_id.token_id account_id in *) @@ -338,7 +338,7 @@ let send_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee ~metadata: [ ( "sender_pub_key" , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) - ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ; ("node_uri", `String (Uri.to_string node_uri)) ] ; let open Deferred.Or_error.Let_syntax in let sender_pk_str = @@ -392,7 +392,7 @@ let send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee = ~metadata: [ ( "sender_pub_key" , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) - ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ; ("node_uri", `String (Uri.to_string node_uri)) ] ; let open Deferred.Or_error.Let_syntax in let sender_pk_str = @@ -449,7 +449,7 @@ let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key ~metadata: [ ( "sender_pub_key" , Signature_lib.Public_key.Compressed.to_yojson sender_pub_key ) - ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ; ("node_uri", `String (Uri.to_string node_uri)) ] ; let open Deferred.Or_error.Let_syntax in let send_payment_graphql () = @@ -498,7 +498,7 @@ let send_test_payments ~(repeat_count : Unsigned.UInt32.t) ~(senders : Import.Private_key.t list) ~(receiver_pub_key : Account.key) ~amount ~fee = [%log info] "Sending a series of test payments" - ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + ~metadata:[ ("node_uri", `String (Uri.to_string node_uri)) ] ; let open Deferred.Or_error.Let_syntax in let send_payment_graphql () = let send_payment_obj = @@ -526,7 +526,7 @@ let set_snark_worker ~logger node_uri ~new_snark_pub_key = ~metadata: [ ( "new_snark_pub_key" , Signature_lib.Public_key.Compressed.to_yojson new_snark_pub_key ) - ; ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) + ; ("node_uri", `String (Uri.to_string node_uri)) ] ; let open Deferred.Or_error.Let_syntax in let set_snark_worker_graphql () = @@ -559,7 +559,7 @@ let must_set_snark_worker ~logger t ~new_snark_pub_key = let get_metrics ~logger node_uri = let open Deferred.Or_error.Let_syntax in [%log info] "Getting node's metrics" - ~metadata:[ ("node_uri", Yojson.Safe.from_string (Uri.to_string node_uri)) ] ; + ~metadata:[ ("node_uri", `String (Uri.to_string node_uri)) ] ; let query_obj = Graphql.Query_metrics.make () in let%bind query_result_obj = exec_graphql_request ~logger ~node_uri ~query_name:"query_metrics" query_obj From af9605f41dbd1ecc2ac1c7dd5d4afe70806e552b Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Tue, 20 Jun 2023 21:19:10 +0200 Subject: [PATCH 05/15] refactor payments test for better way to create the payment with raw sig --- src/app/test_executive/payments_test.ml | 146 +++++++++--------------- 1 file changed, 51 insertions(+), 95 deletions(-) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 686f95c0b41..ef4be80aeb1 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -105,6 +105,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let fish2 = Core.String.Map.find_exn (Network.genesis_keypairs network) "fish2" in + (* hardcoded values of the balances of fish1 (receiver) and fish2 (sender), update here if they change in the config *) + (* TODO undo the harcoding, don't be lazy and just make the graphql commands to fetch the balances *) + let receiver_original_balance = Currency.Amount.of_formatted_string "100" in + let sender_original_balance = Currency.Amount.of_formatted_string "100" in + let sender = fish2.keypair in + let receiver = fish1.keypair in [%log info] "extra genesis keypairs: %s" (List.to_string [ fish1.keypair; fish2.keypair ] ~f:(fun { Signature_lib.Keypair.public_key; _ } -> @@ -128,62 +134,46 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~f:(fun { Signature_lib.Keypair.public_key; _ } -> public_key |> Signature_lib.Public_key.to_yojson |> Yojson.Safe.to_string ) ) ; - (* create a signed txn which we'll use to make a successfull txn, and then a replay attack *) - let amount = Currency.Amount.of_formatted_string "10" in - let fee = Currency.Fee.of_formatted_string "1" in - let test_constants = Engine.Network.constraint_constants network in + (* setup code, creating a signed txn which we'll use to make a successful txn, and then use the same txn in a replay attack which should fail *) let receiver_pub_key = - fish1.keypair.public_key |> Signature_lib.Public_key.compress + receiver.public_key |> Signature_lib.Public_key.compress in let sender_pub_key = - fish2.keypair.public_key |> Signature_lib.Public_key.compress - in - (* hardcoded copy of extra_genesis_accounts[0] and extra_genesis_accounts[1], update here if they change *) - let receiver_original_balance = Currency.Amount.of_formatted_string "100" in - let sender_original_balance = Currency.Amount.of_formatted_string "100" in - let txn_body = - Signed_command_payload.Body.Payment - { source_pk = sender_pub_key - ; receiver_pk = receiver_pub_key - ; token_id = Token_id.default - ; amount - } + sender.public_key |> Signature_lib.Public_key.compress in let%bind { nonce = sender_current_nonce; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) ~public_key:sender_pub_key in - let user_command_input = - User_command_input.create ~fee ~nonce:sender_current_nonce - ~fee_token:(Signed_command_payload.Body.token txn_body) - ~fee_payer_pk:sender_pub_key ~valid_until:None - ~memo:(Signed_command_memo.create_from_string_exn "") - ~body:txn_body ~signer:sender_pub_key - ~sign_choice:(User_command_input.Sign_choice.Keypair fish2.keypair) () - in - [%log info] "user_command_input: $user_command" - ~metadata: - [ ( "user_command" - , User_command_input.Stable.Latest.to_yojson user_command_input ) - ] ; - let%bind txn_signed = - User_command_input.to_user_command - ~get_current_nonce:(fun _ -> failwith "get_current_nonce, don't call me") - ~nonce_map: - (Account_id.Map.of_alist_exn - [ ( Account_id.create sender_pub_key - (Signed_command_payload.Body.token txn_body) - , (sender_current_nonce, sender_current_nonce) ) - ] ) - ~get_account:(fun _ -> `Bootstrapping) - ~constraint_constants:test_constants ~logger user_command_input - |> Deferred.bind ~f:Malleable_error.or_hard_error + let amount = Currency.Amount.of_formatted_string "10" in + let fee = Currency.Fee.of_formatted_string "1" in + let memo = "" in + let token = Token_id.default in + let valid_until = Mina_numbers.Global_slot.max_value in + let payload = + let payment_payload = + { Payment_payload.Poly.receiver_pk = receiver_pub_key + ; source_pk = sender_pub_key + ; token_id = token + ; amount + } + in + let body = Signed_command_payload.Body.Payment payment_payload in + let common = + { Signed_command_payload.Common.Poly.fee + ; fee_token = Signed_command_payload.Body.token body + ; fee_payer_pk = sender_pub_key + ; nonce = sender_current_nonce + ; valid_until = Mina_numbers.Global_slot.max_value + ; memo = Signed_command_memo.create_from_string_exn memo + } + in + { Signed_command_payload.Poly.common; body } in - let (signed_cmmd, _) - : Signed_command.t - * (Unsigned.uint32 * Unsigned.uint32) Account_id.Map.t = - txn_signed + let raw_signature = + Signed_command.sign_payload sender.private_key payload + |> Signature.Raw.encode in (* setup complete *) let%bind () = @@ -192,22 +182,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_b) ~logger - ~sender_pub_key: - (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) - ~receiver_pub_key: - (Signed_command_payload.Body.receiver_pk signed_cmmd.payload.body) - ~amount: - ( Signed_command_payload.amount signed_cmmd.payload - |> Option.value_exn ) - ~fee:(Signed_command_payload.fee signed_cmmd.payload) - ~nonce:signed_cmmd.payload.common.nonce - ~memo: - (Signed_command_memo.to_raw_bytes_exn - signed_cmmd.payload.common.memo ) - ~token:(Signed_command_payload.token signed_cmmd.payload) - ~valid_until:signed_cmmd.payload.common.valid_until - ~raw_signature: - (Mina_base.Signature.Raw.encode signed_cmmd.signature) + ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) + ~amount ~fee + ~nonce:(Signed_command_payload.nonce payload) + ~memo ~token ~valid_until ~raw_signature in wait_for t (Wait_condition.signed_command_to_be_included_in_frontier @@ -286,22 +265,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_b) ~logger - ~sender_pub_key: - (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) - ~receiver_pub_key: - (Signed_command_payload.Body.receiver_pk signed_cmmd.payload.body) - ~amount: - ( Signed_command_payload.amount signed_cmmd.payload - |> Option.value_exn ) - ~fee:(Signed_command_payload.fee signed_cmmd.payload) - ~nonce:signed_cmmd.payload.common.nonce - ~memo: - (Signed_command_memo.to_raw_bytes_exn - signed_cmmd.payload.common.memo ) - ~token:(Signed_command_payload.token signed_cmmd.payload) - ~valid_until:signed_cmmd.payload.common.valid_until - ~raw_signature: - (Mina_base.Signature.Raw.encode signed_cmmd.signature) + ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) + ~amount ~fee + ~nonce:(Signed_command_payload.nonce payload) + ~memo ~token ~valid_until ~raw_signature with | Ok { nonce; _ } -> Malleable_error.soft_error_format ~value:() @@ -336,23 +304,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_a) ~logger - ~sender_pub_key: - (Signed_command_payload.Body.source_pk signed_cmmd.payload.body) - ~receiver_pub_key: - (Signed_command_payload.Body.receiver_pk signed_cmmd.payload.body) - ~amount: - ( Signed_command_payload.amount signed_cmmd.payload - |> Option.value_exn ) - ~fee:(Signed_command_payload.fee signed_cmmd.payload) - ~nonce: - (Mina_numbers.Account_nonce.succ signed_cmmd.payload.common.nonce) - ~memo: - (Signed_command_memo.to_raw_bytes_exn - signed_cmmd.payload.common.memo ) - ~token:(Signed_command_payload.token signed_cmmd.payload) - ~valid_until:signed_cmmd.payload.common.valid_until - ~raw_signature: - (Mina_base.Signature.Raw.encode signed_cmmd.signature) + ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) + ~amount ~fee + ~nonce:(Signed_command_payload.nonce payload) + ~memo ~token ~valid_until ~raw_signature with | Ok { nonce; _ } -> Malleable_error.soft_error_format ~value:() From 2db81b2f5843094b097bb9d74f32f71c36d13ab8 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Wed, 21 Jun 2023 18:32:27 +0200 Subject: [PATCH 06/15] gotta succ the nonce --- src/app/test_executive/payments_test.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index ef4be80aeb1..ebf5c43946e 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -307,7 +307,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~sender_pub_key:(Signed_command_payload.source_pk payload) ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) ~amount ~fee - ~nonce:(Signed_command_payload.nonce payload) + ~nonce: + (Mina_numbers.Account_nonce.succ + (Signed_command_payload.nonce payload) ) ~memo ~token ~valid_until ~raw_signature with | Ok { nonce; _ } -> From 769be13f1da0f125447ea54cdd48b3ee38b54169 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Wed, 21 Jun 2023 18:33:58 +0200 Subject: [PATCH 07/15] minor change --- src/app/test_executive/payments_test.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index ebf5c43946e..94b8ed52281 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -316,7 +316,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Malleable_error.soft_error_format ~value:() "Replay attack succeeded, but it should fail because the \ signature is wrong. attempted nonce: %d" - (Unsigned.UInt32.to_int nonce) + (Unsigned.UInt32.to_int (Signed_command_payload.nonce payload)) | Error error -> (* expect GraphQL error due to invalid signature *) let err_str = Error.to_string_mach error in From f72d26d4633f1ad93deeaad49876cc01520a8383 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Thu, 22 Jun 2023 13:24:27 +0200 Subject: [PATCH 08/15] modernize batch txn tool and fix errors --- src/app/batch_txn_tool/batch_txn_tool.ml | 163 ++++++---- src/app/batch_txn_tool/dune | 4 + src/app/batch_txn_tool/txn_tool_graphql.ml | 284 +++++++++--------- src/app/test_executive/payments_test.ml | 14 +- src/app/test_executive/test_common.ml | 4 +- .../integration_test_lib/graphql_requests.ml | 42 ++- 6 files changed, 295 insertions(+), 216 deletions(-) diff --git a/src/app/batch_txn_tool/batch_txn_tool.ml b/src/app/batch_txn_tool/batch_txn_tool.ml index 27fa8d48ae5..e931d2b440c 100644 --- a/src/app/batch_txn_tool/batch_txn_tool.ml +++ b/src/app/batch_txn_tool/batch_txn_tool.ml @@ -1,8 +1,11 @@ open Core open Async open Signature_lib -open Txn_tool_graphql + +(* open Txn_tool_graphql *) open Unsigned +open Mina_base +open Integration_test_lib let gen_keys count = Quickcheck.random_value ~seed:`Nondeterministic @@ -89,8 +92,63 @@ let output_cmds = (Public_key.Compressed.to_base58_check pk) sender_key ) ) -let pk_to_str pk = - pk |> Public_key.compress |> Public_key.Compressed.to_base58_check +let pub_key_to_string pub_key = + pub_key |> Public_key.compress |> Public_key.Compressed.to_base58_check + +let ingress_uri ~graphql_target_node = + let target = Str.split (Str.regexp ":") graphql_target_node in + let host = + match List.nth target 0 with Some data -> data | None -> "127.0.0.1" + in + let port = + match List.nth target 1 with + | Some data -> + int_of_string data + | None -> + 3085 + in + let path = "/graphql" in + Uri.make ~scheme:"http" ~host ~path ~port () + +(* helper function that uses graphql command to get the nonce of a node*) +let get_nonce ~logger ~(ingress_uri : Uri.t) ~(pub_key : Account.key) = + [%log info] "txn burst tool: Getting account balance and nonce" + ~metadata: + [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pub_key) + ; ("ingress_uri", `String (Uri.to_string ingress_uri)) + ] ; + let%bind nonce = + let%bind querry_result = + Integration_test_lib.Graphql_requests.get_account_data ingress_uri ~logger + ~public_key:pub_key + in + match querry_result with + | Ok res -> + return res.nonce + | Error _ -> + [%log error] "txn burst tool: could not get nonce of pk" + ~metadata: + [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pub_key) + ; ("ingress_uri", `String (Uri.to_string ingress_uri)) + ] ; + exit 1 + in + [%log info] "txn burst tool: nonce obtained, nonce= %d" (UInt32.to_int nonce) ; + return nonce + +(* helper function for getting a keypair from a local path *) +let get_keypair ~logger path pw_option = + let%bind keypair = + match pw_option with + | Some s -> + Secrets.Keypair.read_exn ~privkey_path:path + ~password:(s |> Bytes.of_string |> Deferred.return |> Lazy.return) + | None -> + Secrets.Keypair.read_exn' path + in + [%log info] "txn burst tool: successfully got keypair. pub_key= %s " + (pub_key_to_string keypair.public_key) ; + return keypair let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate ~txn_fee_option ~rate_limit ~rate_limit_level ~rate_limit_interval @@ -100,6 +158,8 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate ~graphql_target_node_option () = let open Deferred.Let_syntax in (* define the rate limiting function *) + let open Logger in + let logger = Logger.create () in let limit_level = let slot_limit = Float.( @@ -117,10 +177,14 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate if !batch_count >= limit_level then let%bind () = Deferred.return - (Format.printf - "txn burst tool: rate limiting, pausing for %d milliseconds... \ - @." - rate_limit_interval ) + ([%log info] + "txn burst tool: rate limiting, pausing for %d milliseconds... " + rate_limit_interval + ~metadata: + [ ( "rate_limit_interval" + , rate_limit_interval |> Int.to_string + |> Yojson.Safe.from_string ) + ] ) in let%bind () = Async.after (Time.Span.create ~ms:rate_limit_interval ()) @@ -130,7 +194,7 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate else fun () -> Deferred.return () in - (* contants regarding send amount and fees *) + (* constants regarding send amount and fees *) let base_send_amount = Currency.Amount.of_formatted_string "0" in let fee_amount = match txn_fee_option with @@ -167,78 +231,46 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate let graphql_target_node = match graphql_target_node_option with Some s -> s | None -> "127.0.0.1" in - - (* helper function for getting a keypair from a local path *) - let get_keypair path pw_option = - let%bind keypair = - match pw_option with - | Some s -> - Secrets.Keypair.read_exn ~privkey_path:path - ~password:(s |> Bytes.of_string |> Deferred.return |> Lazy.return) - | None -> - Secrets.Keypair.read_exn' path - in - let pk_str = - keypair.public_key |> Public_key.compress - |> Public_key.Compressed.to_base58_check - in - Format.printf "txn burst tool: successfully got keypair. pk= %s@." pk_str ; - return keypair - in + let node_ingress_uri = ingress_uri ~graphql_target_node in (* get the keypairs from files *) let%bind origin_keypair = - get_keypair origin_sender_secret_key_path origin_sender_secret_key_pw_option + get_keypair ~logger origin_sender_secret_key_path + origin_sender_secret_key_pw_option in - let%bind returner_keypair = - get_keypair returner_secret_key_path returner_secret_key_pw_option + let origin_pub_key = + origin_keypair.public_key |> Signature_lib.Public_key.compress in - - (* helper function that uses graphql command to get the nonce of a node*) - let get_nonce pk = - Format.printf - "txn burst tool: using graphql to get the nonce of the account= %s, \ - using graphql target node= %s@." - (pk_to_str pk) graphql_target_node ; - let%bind nonce = - let%bind querry_result = - get_account_data ~graphql_target_node ~public_key:pk - in - match querry_result with - | Ok n -> - return (UInt32.of_int n) - | Error _ -> - Format.printf "txn burst tool: could not get nonce of pk= %s@." - (pk_to_str pk) ; - exit 1 - in - Format.printf "txn burst tool: nonce obtained, nonce= %d@." - (UInt32.to_int nonce) ; - return nonce + let%bind returner_keypair = + get_keypair ~logger returner_secret_key_path returner_secret_key_pw_option in (* helper function that sends a transaction*) let do_txn ~(sender_kp : Keypair.t) ~(receiver_kp : Keypair.t) ~nonce = - Format.printf + let receiver_pub_key = + receiver_kp.public_key |> Signature_lib.Public_key.compress + in + [%log info] "txn burst tool: sending txn from sender= %s (nonce=%d) to receiver= %s \ - with amount=%s and fee=%s@." - (pk_to_str sender_kp.public_key) + with amount=%s and fee=%s" + (pub_key_to_string sender_kp.public_key) (UInt32.to_int nonce) - (pk_to_str receiver_kp.public_key) + (pub_key_to_string receiver_kp.public_key) (Currency.Amount.to_string initial_send_amount) (Currency.Fee.to_string fee_amount) ; let%bind res = - send_signed_transaction ~sender_priv_key:sender_kp.private_key ~nonce - ~receiver_pub_key:receiver_kp.public_key ~amount:initial_send_amount - ~fee:fee_amount ~graphql_target_node + Graphql_requests.sign_and_send_payment ~logger node_ingress_uri + ~sender_keypair:sender_kp ~receiver_pub_key ~amount:base_send_amount + ~fee:fee_amount ~nonce ~memo:"" ~token:Token_id.default + ~valid_until:Mina_numbers.Global_slot.max_value in let%bind () = match res with | Ok _ -> - return (Format.printf "txn burst tool: txn sent successfully!@.") + return ([%log info] "txn burst tool: txn sent successfully!") | Error e -> return - (Format.printf "txn burst tool: txn failed with error %s@." + ([%log info] "txn burst tool: txn failed with error %s" (Error.to_string_hum e) ) in limit () @@ -248,7 +280,10 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate let%bind () = (* in a previous version of the code there could be multiple returners, thus the iter. keeping this structure in case we decide to change back later *) Deferred.List.iter [ returner_keypair ] ~f:(fun kp -> - let%bind origin_nonce = get_nonce origin_keypair.public_key in + let%bind origin_nonce = + get_nonce ~logger ~ingress_uri:node_ingress_uri + ~pub_key:origin_pub_key + in (* we could also get the origin nonce outside the iter and then just increment by 1 every iter *) do_txn ~sender_kp:origin_keypair ~receiver_kp:kp ~nonce:origin_nonce ) in @@ -256,7 +291,10 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate (* and back again... *) let%bind () = Deferred.List.iter [ returner_keypair ] ~f:(fun kp -> - let%bind returner_nonce = get_nonce kp.public_key in + let%bind returner_nonce = + get_nonce ~logger ~ingress_uri:node_ingress_uri + ~pub_key:(Signature_lib.Public_key.compress kp.public_key) + in let rec do_command n : unit Deferred.t = (* nce = returner_nonce + ( num_txn_per_acct - n ) *) let nce = @@ -269,6 +307,7 @@ let there_and_back_again ~num_txn_per_acct ~txns_per_block ~slot_time ~fill_rate in do_command num_txn_per_acct ) in + return () let output_there_and_back_cmds = diff --git a/src/app/batch_txn_tool/dune b/src/app/batch_txn_tool/dune index 4206a319e36..ce7057294fb 100644 --- a/src/app/batch_txn_tool/dune +++ b/src/app/batch_txn_tool/dune @@ -21,11 +21,15 @@ mina_numbers snark_params unsigned_extended + integration_test_lib + logger + ) (instrumentation (backend bisect_ppx)) (preprocess (pps ppx_version ppx_let + ppx_coda graphql_ppx -- -extend-query Graphql_lib.Serializing.ExtendQuery -extend-mutation Graphql_lib.Serializing.ExtendQuery diff --git a/src/app/batch_txn_tool/txn_tool_graphql.ml b/src/app/batch_txn_tool/txn_tool_graphql.ml index 3aa75b7cddf..2aa4f886a74 100644 --- a/src/app/batch_txn_tool/txn_tool_graphql.ml +++ b/src/app/batch_txn_tool/txn_tool_graphql.ml @@ -1,151 +1,151 @@ -open Core -open Async -open Signature_lib -module Serializing = Graphql_lib.Serializing +(* open Core + open Async + open Signature_lib + module Serializing = Graphql_lib.Serializing -module Client = Graphql_lib.Client.Make (struct - let preprocess_variables_string = Fn.id + module Client = Graphql_lib.Client.Make (struct + let preprocess_variables_string = Fn.id - let headers = String.Map.empty -end) + let headers = String.Map.empty + end) -let ingress_uri ~graphql_target_node = - let target = Str.split (Str.regexp ":") graphql_target_node in - let host = - match List.nth target 0 with Some data -> data | None -> "127.0.0.1" - in - let port = - match List.nth target 1 with - | Some data -> - int_of_string data - | None -> - 3085 - in - let path = "/graphql" in - Uri.make ~scheme:"http" ~host ~path ~port () + let ingress_uri ~graphql_target_node = + let target = Str.split (Str.regexp ":") graphql_target_node in + let host = + match List.nth target 0 with Some data -> data | None -> "127.0.0.1" + in + let port = + match List.nth target 1 with + | Some data -> + int_of_string data + | None -> + 3085 + in + let path = "/graphql" in + Uri.make ~scheme:"http" ~host ~path ~port () -(* this function will repeatedly attempt to connect to graphql port times before giving up *) -(* copied from src/lib/integration_test_cloud_engine/kubernetes_network.ml and tweaked *) -let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) - ?(initial_delay_sec = 30.0) ~graphql_target_node query_obj = - let open Deferred.Let_syntax in - let uri = ingress_uri ~graphql_target_node in - let rec retry n = - if n <= 0 then - Deferred.Or_error.errorf "GraphQL request to %s failed too many times" - graphql_target_node - else - match%bind Client.query query_obj uri with - | Ok result -> - Deferred.Or_error.return result - | Error (`Failed_request _) -> - let%bind () = after (Time.Span.of_sec retry_delay_sec) in - retry (n - 1) - | Error (`Graphql_error err_string) -> - Deferred.Or_error.error_string err_string - in - let%bind () = after (Time.Span.of_sec initial_delay_sec) in - retry num_tries + (* this function will repeatedly attempt to connect to graphql port times before giving up *) + (* copied from src/lib/integration_test_cloud_engine/kubernetes_network.ml and tweaked *) + let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) + ?(initial_delay_sec = 30.0) ~graphql_target_node query_obj = + let open Deferred.Let_syntax in + let uri = ingress_uri ~graphql_target_node in + let rec retry n = + if n <= 0 then + Deferred.Or_error.errorf "GraphQL request to %s failed too many times" + graphql_target_node + else + match%bind Client.query query_obj uri with + | Ok result -> + Deferred.Or_error.return result + | Error (`Failed_request _) -> + let%bind () = after (Time.Span.of_sec retry_delay_sec) in + retry (n - 1) + | Error (`Graphql_error err_string) -> + Deferred.Or_error.error_string err_string + in + let%bind () = after (Time.Span.of_sec initial_delay_sec) in + retry num_tries -(* copied from src/app/cli/src/init/graphql_queries.ml and tweaked*) -module Send_payment = -[%graphql -{| -mutation ($sender: PublicKey!, - $receiver: PublicKey!, - $amount: UInt64!, - $token: UInt64, - $fee: UInt64!, - $nonce: UInt32, - $memo: String, - $field: String, - $scalar: String) { - sendPayment(input: - {from: $sender, to: $receiver, amount: $amount, token: $token, fee: $fee, nonce: $nonce, memo: $memo}, - signature: {field: $field, scalar: $scalar}) { - payment { - id - } - } -} -|}] + (* copied from src/app/cli/src/init/graphql_queries.ml and tweaked*) + module Send_payment = + [%graphql + {| + mutation ($sender: PublicKey!, + $receiver: PublicKey!, + $amount: UInt64!, + $token: UInt64, + $fee: UInt64!, + $nonce: UInt32, + $memo: String, + $field: String, + $scalar: String) { + sendPayment(input: + {from: $sender, to: $receiver, amount: $amount, token: $token, fee: $fee, nonce: $nonce, memo: $memo}, + signature: {field: $field, scalar: $scalar}) { + payment { + id + } + } + } + |}] -module Get_account_data = -[%graphql -{| -query ($public_key: PublicKey!) { - account(publicKey: $public_key) { - nonce - balance { - total - liquid - locked - } - } -} -|}] + module Get_account_data = + [%graphql + {| + query ($public_key: PublicKey!) { + account(publicKey: $public_key) { + nonce + balance { + total + liquid + locked + } + } + } + |}] -let get_account_data ~public_key ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let pk = public_key |> Public_key.compress in - let get_acct_data_obj = - Get_account_data.( - make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) - in - let%bind balance_obj = - exec_graphql_request ~graphql_target_node get_acct_data_obj - in - match balance_obj.account with - | None -> - Deferred.Or_error.errorf "Account with %s not found" - (Public_key.Compressed.to_string pk) - | Some acc -> ( - match acc.nonce with - | Some s -> - return (int_of_string s) - | None -> - Deferred.Or_error.errorf "Account with %s somehow doesnt have a nonce" - (Public_key.Compressed.to_string pk) ) + let get_account_data ~public_key ~graphql_target_node = + let open Deferred.Or_error.Let_syntax in + let pk = public_key |> Public_key.compress in + let get_acct_data_obj = + Get_account_data.( + make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) + in + let%bind balance_obj = + exec_graphql_request ~graphql_target_node get_acct_data_obj + in + match balance_obj.account with + | None -> + Deferred.Or_error.errorf "Account with %s not found" + (Public_key.Compressed.to_string pk) + | Some acc -> ( + match acc.nonce with + | Some s -> + return (int_of_string s) + | None -> + Deferred.Or_error.errorf "Account with %s somehow doesnt have a nonce" + (Public_key.Compressed.to_string pk) ) -let send_signed_transaction ~sender_priv_key ~nonce ~receiver_pub_key ~amount - ~fee ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let sender_pub_key = - Public_key.of_private_key_exn sender_priv_key |> Public_key.compress - in - let receiver_pk = receiver_pub_key |> Public_key.compress in + let send_signed_transaction ~sender_priv_key ~nonce ~receiver_pub_key ~amount + ~fee ~graphql_target_node = + let open Deferred.Or_error.Let_syntax in + let sender_pub_key = + Public_key.of_private_key_exn sender_priv_key |> Public_key.compress + in + let receiver_pk = receiver_pub_key |> Public_key.compress in - let field, scalar = - Mina_base.Signed_command.sign_payload sender_priv_key - { common = - { fee - ; fee_token = Mina_base.Token_id.default - ; fee_payer_pk = sender_pub_key - ; nonce - ; valid_until = Mina_numbers.Global_slot.max_value - ; memo = Mina_base.Signed_command_memo.empty - } - ; body = - Payment - { source_pk = sender_pub_key - ; receiver_pk - ; token_id = Mina_base.Token_id.default - ; amount - } - } - in - let graphql_query = - Send_payment.( - make - @@ makeVariables - ~receiver:(Graphql_lib.Encoders.public_key receiver_pk) - ~sender:(Graphql_lib.Encoders.public_key sender_pub_key) - ~amount:(Graphql_lib.Encoders.amount amount) - ~fee:(Graphql_lib.Encoders.fee fee) - ~nonce:(Graphql_lib.Encoders.nonce nonce) - ~field:(Snark_params.Tick.Field.to_string field) - ~scalar:(Snark_params.Tick.Inner_curve.Scalar.to_string scalar) - ()) - in - let%map res = exec_graphql_request ~graphql_target_node graphql_query in - res.sendPayment.payment.id + let field, scalar = + Mina_base.Signed_command.sign_payload sender_priv_key + { common = + { fee + ; fee_token = Mina_base.Token_id.default + ; fee_payer_pk = sender_pub_key + ; nonce + ; valid_until = Mina_numbers.Global_slot.max_value + ; memo = Mina_base.Signed_command_memo.empty + } + ; body = + Payment + { source_pk = sender_pub_key + ; receiver_pk + ; token_id = Mina_base.Token_id.default + ; amount + } + } + in + let graphql_query = + Send_payment.( + make + @@ makeVariables + ~receiver:(Graphql_lib.Encoders.public_key receiver_pk) + ~sender:(Graphql_lib.Encoders.public_key sender_pub_key) + ~amount:(Graphql_lib.Encoders.amount amount) + ~fee:(Graphql_lib.Encoders.fee fee) + ~nonce:(Graphql_lib.Encoders.nonce nonce) + ~field:(Snark_params.Tick.Field.to_string field) + ~scalar:(Snark_params.Tick.Inner_curve.Scalar.to_string scalar) + ()) + in + let%map res = exec_graphql_request ~graphql_target_node graphql_query in + res.sendPayment.payment.id *) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 94b8ed52281..9fdc898d4fd 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -165,7 +165,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ; fee_token = Signed_command_payload.Body.token body ; fee_payer_pk = sender_pub_key ; nonce = sender_current_nonce - ; valid_until = Mina_numbers.Global_slot.max_value + ; valid_until ; memo = Signed_command_memo.create_from_string_exn memo } in @@ -312,11 +312,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Signed_command_payload.nonce payload) ) ~memo ~token ~valid_until ~raw_signature with - | Ok { nonce; _ } -> + | Ok { nonce = returned_nonce; _ } -> Malleable_error.soft_error_format ~value:() "Replay attack succeeded, but it should fail because the \ - signature is wrong. attempted nonce: %d" + signature is wrong. payload nonce: %d. returned nonce: %d" (Unsigned.UInt32.to_int (Signed_command_payload.nonce payload)) + (Unsigned.UInt32.to_int returned_nonce) | Error error -> (* expect GraphQL error due to invalid signature *) let err_str = Error.to_string_mach error in @@ -332,7 +333,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "Payment failed in GraphQL, but for unexpected reason: %s" err_str ; Malleable_error.soft_error_format ~value:() - "Payment failed for unexpected reason: %s" err_str )) + "Payment failed, but for unexpected reason: %s" err_str )) in let%bind () = section "send a single payment from timed account using available liquid" @@ -342,7 +343,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = timed_node_c in let%bind sender_pub_key = pub_key_of_node sender in let%bind { hash; _ } = - Integration_test_lib.Graphql_requests.must_send_payment ~logger + Integration_test_lib.Graphql_requests.must_send_online_payment + ~logger (Network.Node.get_ingress_uri timed_node_c) ~sender_pub_key ~receiver_pub_key ~amount ~fee in @@ -371,7 +373,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (* TODO: refactor this using new [expect] dsl when it's available *) let open Deferred.Let_syntax in match%bind - Integration_test_lib.Graphql_requests.send_payment ~logger + Integration_test_lib.Graphql_requests.send_online_payment ~logger (Network.Node.get_ingress_uri sender) ~sender_pub_key ~receiver_pub_key ~amount ~fee with diff --git a/src/app/test_executive/test_common.ml b/src/app/test_executive/test_common.ml index 00cecad5961..a83777683f9 100644 --- a/src/app/test_executive/test_common.ml +++ b/src/app/test_executive/test_common.ml @@ -27,8 +27,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct else let%bind hash = let%map { hash; nonce; _ } = - Integration_test_lib.Graphql_requests.must_send_payment ~logger - ~sender_pub_key ~receiver_pub_key ~amount ~fee + Integration_test_lib.Graphql_requests.must_send_online_payment + ~logger ~sender_pub_key ~receiver_pub_key ~amount ~fee (Engine.Network.Node.get_ingress_uri node) in [%log info] diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index c0401992f3a..60b0974332e 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -332,8 +332,8 @@ type signed_command_result = { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } (* if we expect failure, might want retry_on_graphql_error to be false *) -let send_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee - = +let send_online_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key + ~amount ~fee = [%log info] "Sending a payment" ~metadata: [ ( "sender_pub_key" @@ -383,8 +383,9 @@ let send_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee ] ; res -let must_send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee = - send_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee +let must_send_online_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount + ~fee = + send_online_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee |> Deferred.bind ~f:Malleable_error.or_hard_error let send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee = @@ -493,6 +494,39 @@ let must_send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature |> Deferred.bind ~f:Malleable_error.or_hard_error +let sign_and_send_payment ~logger node_uri + ~(sender_keypair : Import.Signature_keypair.t) ~receiver_pub_key ~amount + ~fee ~nonce ~memo ~token ~valid_until = + let sender_pub_key = + sender_keypair.public_key |> Signature_lib.Public_key.compress + in + let payload = + let payment_payload = + { Payment_payload.Poly.receiver_pk = receiver_pub_key + ; source_pk = sender_pub_key + ; token_id = token + ; amount + } + in + let body = Signed_command_payload.Body.Payment payment_payload in + let common = + { Signed_command_payload.Common.Poly.fee + ; fee_token = Signed_command_payload.Body.token body + ; fee_payer_pk = sender_pub_key + ; nonce + ; valid_until + ; memo = Signed_command_memo.create_from_string_exn memo + } + in + { Signed_command_payload.Poly.common; body } + in + let raw_signature = + Signed_command.sign_payload sender_keypair.private_key payload + |> Signature.Raw.encode + in + send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key + ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature + let send_test_payments ~(repeat_count : Unsigned.UInt32.t) ~(repeat_delay_ms : Unsigned.UInt32.t) ~logger node_uri ~(senders : Import.Private_key.t list) ~(receiver_pub_key : Account.key) From 8eadf933c603cad043be422a883a02e33d64a659 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Thu, 22 Jun 2023 14:04:01 +0200 Subject: [PATCH 09/15] cleaning up --- src/app/batch_txn_tool/batch_txn_tool.ml | 2 - src/app/batch_txn_tool/txn_tool_graphql.ml | 151 ------------------ .../integration_test_lib/graphql_requests.ml | 22 ++- 3 files changed, 15 insertions(+), 160 deletions(-) delete mode 100644 src/app/batch_txn_tool/txn_tool_graphql.ml diff --git a/src/app/batch_txn_tool/batch_txn_tool.ml b/src/app/batch_txn_tool/batch_txn_tool.ml index e931d2b440c..bcdcd88a304 100644 --- a/src/app/batch_txn_tool/batch_txn_tool.ml +++ b/src/app/batch_txn_tool/batch_txn_tool.ml @@ -1,8 +1,6 @@ open Core open Async open Signature_lib - -(* open Txn_tool_graphql *) open Unsigned open Mina_base open Integration_test_lib diff --git a/src/app/batch_txn_tool/txn_tool_graphql.ml b/src/app/batch_txn_tool/txn_tool_graphql.ml deleted file mode 100644 index 2aa4f886a74..00000000000 --- a/src/app/batch_txn_tool/txn_tool_graphql.ml +++ /dev/null @@ -1,151 +0,0 @@ -(* open Core - open Async - open Signature_lib - module Serializing = Graphql_lib.Serializing - - module Client = Graphql_lib.Client.Make (struct - let preprocess_variables_string = Fn.id - - let headers = String.Map.empty - end) - - let ingress_uri ~graphql_target_node = - let target = Str.split (Str.regexp ":") graphql_target_node in - let host = - match List.nth target 0 with Some data -> data | None -> "127.0.0.1" - in - let port = - match List.nth target 1 with - | Some data -> - int_of_string data - | None -> - 3085 - in - let path = "/graphql" in - Uri.make ~scheme:"http" ~host ~path ~port () - - (* this function will repeatedly attempt to connect to graphql port times before giving up *) - (* copied from src/lib/integration_test_cloud_engine/kubernetes_network.ml and tweaked *) - let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) - ?(initial_delay_sec = 30.0) ~graphql_target_node query_obj = - let open Deferred.Let_syntax in - let uri = ingress_uri ~graphql_target_node in - let rec retry n = - if n <= 0 then - Deferred.Or_error.errorf "GraphQL request to %s failed too many times" - graphql_target_node - else - match%bind Client.query query_obj uri with - | Ok result -> - Deferred.Or_error.return result - | Error (`Failed_request _) -> - let%bind () = after (Time.Span.of_sec retry_delay_sec) in - retry (n - 1) - | Error (`Graphql_error err_string) -> - Deferred.Or_error.error_string err_string - in - let%bind () = after (Time.Span.of_sec initial_delay_sec) in - retry num_tries - - (* copied from src/app/cli/src/init/graphql_queries.ml and tweaked*) - module Send_payment = - [%graphql - {| - mutation ($sender: PublicKey!, - $receiver: PublicKey!, - $amount: UInt64!, - $token: UInt64, - $fee: UInt64!, - $nonce: UInt32, - $memo: String, - $field: String, - $scalar: String) { - sendPayment(input: - {from: $sender, to: $receiver, amount: $amount, token: $token, fee: $fee, nonce: $nonce, memo: $memo}, - signature: {field: $field, scalar: $scalar}) { - payment { - id - } - } - } - |}] - - module Get_account_data = - [%graphql - {| - query ($public_key: PublicKey!) { - account(publicKey: $public_key) { - nonce - balance { - total - liquid - locked - } - } - } - |}] - - let get_account_data ~public_key ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let pk = public_key |> Public_key.compress in - let get_acct_data_obj = - Get_account_data.( - make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) - in - let%bind balance_obj = - exec_graphql_request ~graphql_target_node get_acct_data_obj - in - match balance_obj.account with - | None -> - Deferred.Or_error.errorf "Account with %s not found" - (Public_key.Compressed.to_string pk) - | Some acc -> ( - match acc.nonce with - | Some s -> - return (int_of_string s) - | None -> - Deferred.Or_error.errorf "Account with %s somehow doesnt have a nonce" - (Public_key.Compressed.to_string pk) ) - - let send_signed_transaction ~sender_priv_key ~nonce ~receiver_pub_key ~amount - ~fee ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let sender_pub_key = - Public_key.of_private_key_exn sender_priv_key |> Public_key.compress - in - let receiver_pk = receiver_pub_key |> Public_key.compress in - - let field, scalar = - Mina_base.Signed_command.sign_payload sender_priv_key - { common = - { fee - ; fee_token = Mina_base.Token_id.default - ; fee_payer_pk = sender_pub_key - ; nonce - ; valid_until = Mina_numbers.Global_slot.max_value - ; memo = Mina_base.Signed_command_memo.empty - } - ; body = - Payment - { source_pk = sender_pub_key - ; receiver_pk - ; token_id = Mina_base.Token_id.default - ; amount - } - } - in - let graphql_query = - Send_payment.( - make - @@ makeVariables - ~receiver:(Graphql_lib.Encoders.public_key receiver_pk) - ~sender:(Graphql_lib.Encoders.public_key sender_pub_key) - ~amount:(Graphql_lib.Encoders.amount amount) - ~fee:(Graphql_lib.Encoders.fee fee) - ~nonce:(Graphql_lib.Encoders.nonce nonce) - ~field:(Snark_params.Tick.Field.to_string field) - ~scalar:(Snark_params.Tick.Inner_curve.Scalar.to_string scalar) - ()) - in - let%map res = exec_graphql_request ~graphql_target_node graphql_query in - res.sendPayment.payment.id *) diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index 60b0974332e..ec91d6619dc 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -501,14 +501,14 @@ let sign_and_send_payment ~logger node_uri sender_keypair.public_key |> Signature_lib.Public_key.compress in let payload = - let payment_payload = - { Payment_payload.Poly.receiver_pk = receiver_pub_key - ; source_pk = sender_pub_key - ; token_id = token - ; amount - } + let body = + Signed_command_payload.Body.Payment + { Payment_payload.Poly.receiver_pk = receiver_pub_key + ; source_pk = sender_pub_key + ; token_id = token + ; amount + } in - let body = Signed_command_payload.Body.Payment payment_payload in let common = { Signed_command_payload.Common.Poly.fee ; fee_token = Signed_command_payload.Body.token body @@ -527,6 +527,14 @@ let sign_and_send_payment ~logger node_uri send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature +let must_sign_and_send_payment ~logger node_uri + ~(sender_keypair : Import.Signature_keypair.t) ~receiver_pub_key ~amount + ~fee ~nonce ~memo ~token ~valid_until = + sign_and_send_payment ~logger node_uri + ~(sender_keypair : Import.Signature_keypair.t) + ~receiver_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until + |> Deferred.bind ~f:Malleable_error.or_hard_error + let send_test_payments ~(repeat_count : Unsigned.UInt32.t) ~(repeat_delay_ms : Unsigned.UInt32.t) ~logger node_uri ~(senders : Import.Private_key.t list) ~(receiver_pub_key : Account.key) From cbc9637702aec0ca0c3d9fb5601c6b23f854c579 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Thu, 22 Jun 2023 14:46:38 +0200 Subject: [PATCH 10/15] remove comments --- src/lib/integration_test_lib/intf.ml | 137 --------------------------- 1 file changed, 137 deletions(-) diff --git a/src/lib/integration_test_lib/intf.ml b/src/lib/integration_test_lib/intf.ml index 1bbfcd17367..e985b7d7654 100644 --- a/src/lib/integration_test_lib/intf.ml +++ b/src/lib/integration_test_lib/intf.ml @@ -49,140 +49,6 @@ module Engine = struct val stop : t -> unit Malleable_error.t val get_ingress_uri : t -> Uri.t - (* - type signed_command_result = - { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } - - val send_payment : - logger:Logger.t - -> 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 - -> signed_command_result Deferred.Or_error.t - - val must_send_payment : - logger:Logger.t - -> 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 - -> signed_command_result Malleable_error.t - - val send_payment_with_raw_sig : - logger:Logger.t - -> 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:Mina_numbers.Account_nonce.t - -> memo:string - -> token:Token_id.t - -> valid_until:Mina_numbers.Global_slot.t - -> raw_signature:string - -> signed_command_result Deferred.Or_error.t - - val must_send_payment_with_raw_sig : - logger:Logger.t - -> 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:Mina_numbers.Account_nonce.t - -> memo:string - -> token:Token_id.t - -> valid_until:Mina_numbers.Global_slot.t - -> raw_signature:string - -> signed_command_result Malleable_error.t - - val send_delegation : - logger:Logger.t - -> t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> fee:Currency.Fee.t - -> signed_command_result Deferred.Or_error.t - - val must_send_delegation : - logger:Logger.t - -> t - -> sender_pub_key:Signature_lib.Public_key.Compressed.t - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> fee:Currency.Fee.t - -> signed_command_result Malleable_error.t - - val set_snark_worker : - logger:Logger.t - -> t - -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t - -> unit Deferred.Or_error.t - - val must_set_snark_worker : - logger:Logger.t - -> t - -> new_snark_pub_key:Signature_lib.Public_key.Compressed.t - -> unit Malleable_error.t - - val must_send_test_payments : - repeat_count:Unsigned.uint32 - -> repeat_delay_ms:Unsigned.uint32 - -> logger:Logger.t - -> t - -> senders:Signature_lib.Private_key.t list - -> receiver_pub_key:Signature_lib.Public_key.Compressed.t - -> amount:Currency.Amount.t - -> fee:Currency.Fee.t - -> unit Malleable_error.t - - type account_data = - { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } - - val get_account_data : - logger:Logger.t - -> t - -> public_key:Signature_lib.Public_key.Compressed.t - -> account_data Async_kernel.Deferred.Or_error.t - - val must_get_account_data : - logger:Logger.t - -> t - -> public_key:Signature_lib.Public_key.Compressed.t - -> account_data Malleable_error.t - - val get_filtered_log_entries : - last_log_index_seen:int - -> t - -> string array Async_kernel.Deferred.Or_error.t - - val start_filtered_log : - logger:Logger.t - -> log_filter:string list - -> t - -> unit Async_kernel.Deferred.Or_error.t - - val get_peer_id : - logger:Logger.t - -> t - -> (string * string list) Async_kernel.Deferred.Or_error.t - - val must_get_peer_id : - logger:Logger.t -> t -> (string * string list) Malleable_error.t - - val get_best_chain : - ?max_length:int - -> logger:Logger.t - -> t - -> best_chain_block list Async_kernel.Deferred.Or_error.t - - val must_get_best_chain : - ?max_length:int - -> logger:Logger.t - -> t - -> best_chain_block list Malleable_error.t *) val dump_archive_data : logger:Logger.t -> t -> data_file:string -> unit Malleable_error.t @@ -194,9 +60,6 @@ module Engine = struct val dump_precomputed_blocks : logger:Logger.t -> t -> unit Malleable_error.t - (* - val get_metrics : - logger:Logger.t -> t -> metrics_t Async_kernel.Deferred.Or_error.t *) end type t From 37d2fae631a725785f13e4e0ce04560a5ad6acc1 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Thu, 22 Jun 2023 15:09:42 +0200 Subject: [PATCH 11/15] remove one more comment --- src/app/test_executive/payments_test.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 9fdc898d4fd..6badc3d9dfb 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -78,7 +78,6 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct } let run network t = - (* let open Network in *) let open Malleable_error.Let_syntax in let logger = Logger.create () in let all_nodes = Network.all_nodes network in From 562a4910e0bbbc88974d36054305de85e4b58816 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Tue, 27 Jun 2023 20:17:39 +0200 Subject: [PATCH 12/15] remove file that got brought back in merge --- src/app/batch_txn_tool/dune | 4 - src/app/batch_txn_tool/txn_tool_graphql.ml | 144 --------------------- 2 files changed, 148 deletions(-) delete mode 100644 src/app/batch_txn_tool/txn_tool_graphql.ml diff --git a/src/app/batch_txn_tool/dune b/src/app/batch_txn_tool/dune index 33e717675f4..2d4754f8fe3 100644 --- a/src/app/batch_txn_tool/dune +++ b/src/app/batch_txn_tool/dune @@ -33,8 +33,4 @@ ppx_version ppx_let ppx_mina - ; graphql_ppx -- - ; -extend-query Graphql_lib.Serializing.ExtendQuery - ; -extend-mutation Graphql_lib.Serializing.ExtendQuery - ; -future-added-value false ))) diff --git a/src/app/batch_txn_tool/txn_tool_graphql.ml b/src/app/batch_txn_tool/txn_tool_graphql.ml deleted file mode 100644 index a805bb3fdaf..00000000000 --- a/src/app/batch_txn_tool/txn_tool_graphql.ml +++ /dev/null @@ -1,144 +0,0 @@ -open Core -open Async -open Signature_lib -module Serializing = Graphql_lib.Serializing - -module Client = Graphql_lib.Client.Make (struct - let preprocess_variables_string = Fn.id - - let headers = String.Map.empty -end) - -let ingress_uri ~graphql_target_node = - let target = Str.split (Str.regexp ":") graphql_target_node in - let host = - match List.nth target 0 with Some data -> data | None -> "127.0.0.1" - in - let port = - match List.nth target 1 with - | Some data -> - int_of_string data - | None -> - 3085 - in - let path = "/graphql" in - Uri.make ~scheme:"http" ~host ~path ~port () - -(* this function will repeatedly attempt to connect to graphql port times before giving up *) -(* copied from src/lib/integration_test_cloud_engine/kubernetes_network.ml and tweaked *) -let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) - ?(initial_delay_sec = 30.0) ~graphql_target_node query_obj = - let open Deferred.Let_syntax in - let uri = ingress_uri ~graphql_target_node in - let rec retry n = - if n <= 0 then - Deferred.Or_error.errorf "GraphQL request to %s failed too many times" - graphql_target_node - else - match%bind Client.query query_obj uri with - | Ok result -> - Deferred.Or_error.return result - | Error (`Failed_request _) -> - let%bind () = after (Time.Span.of_sec retry_delay_sec) in - retry (n - 1) - | Error (`Graphql_error err_string) -> - Deferred.Or_error.error_string err_string - in - let%bind () = after (Time.Span.of_sec initial_delay_sec) in - retry num_tries - -(* copied from src/app/cli/src/init/graphql_queries.ml and tweaked*) -module Send_payment = -[%graphql -{| -mutation ($sender: PublicKey!, - $receiver: PublicKey!, - $amount: UInt64!, - $token: UInt64, - $fee: UInt64!, - $nonce: UInt32, - $memo: String, - $field: String, - $scalar: String) { - sendPayment(input: - {from: $sender, to: $receiver, amount: $amount, token: $token, fee: $fee, nonce: $nonce, memo: $memo}, - signature: {field: $field, scalar: $scalar}) { - payment { - id - } - } -} -|}] - -module Get_account_data = -[%graphql -{| -query ($public_key: PublicKey!) { - account(publicKey: $public_key) { - nonce - balance { - total - liquid - locked - } - } -} -|}] - -let get_account_data ~public_key ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let pk = public_key |> Public_key.compress in - let get_acct_data_obj = - Get_account_data.( - make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) - in - let%bind balance_obj = - exec_graphql_request ~graphql_target_node get_acct_data_obj - in - match balance_obj.account with - | None -> - Deferred.Or_error.errorf "Account with %s not found" - (Public_key.Compressed.to_string pk) - | Some acc -> ( - match acc.nonce with - | Some s -> - return s - | None -> - Deferred.Or_error.errorf "Account with %s somehow doesnt have a nonce" - (Public_key.Compressed.to_string pk) ) - -let send_signed_transaction ~sender_priv_key ~nonce ~receiver_pub_key ~amount - ~fee ~graphql_target_node = - let open Deferred.Or_error.Let_syntax in - let sender_pub_key = - Public_key.of_private_key_exn sender_priv_key |> Public_key.compress - in - let receiver_pk = receiver_pub_key |> Public_key.compress in - - let field, scalar = - Mina_base.Signed_command.sign_payload sender_priv_key - { common = - { fee - ; fee_payer_pk = sender_pub_key - ; nonce - ; valid_until = Mina_numbers.Global_slot_since_genesis.max_value - ; memo = Mina_base.Signed_command_memo.empty - } - ; body = Payment { receiver_pk; amount } - } - in - let graphql_query = - Send_payment.( - make - @@ makeVariables - ~receiver:(Graphql_lib.Encoders.public_key receiver_pk) - ~sender:(Graphql_lib.Encoders.public_key sender_pub_key) - ~amount:(Graphql_lib.Encoders.amount amount) - ~fee:(Graphql_lib.Encoders.fee fee) - ~nonce:(Graphql_lib.Encoders.nonce nonce) - ~field:(Snark_params.Tick.Field.to_string field) - ~scalar:(Snark_params.Tick.Inner_curve.Scalar.to_string scalar) - ()) - in - let%map res = exec_graphql_request ~graphql_target_node graphql_query in - res.sendPayment.payment.id From 765c9534c77b229253a562ef3855f15dc8c924e8 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Wed, 28 Jun 2023 16:14:14 +0200 Subject: [PATCH 13/15] make graphql logic conform to berkeley standards and interfaces --- src/app/test_executive/block_reward_test.ml | 2 +- src/app/test_executive/dune | 1 + src/app/test_executive/payments_test.ml | 119 +++-- .../test_executive/peers_reliability_test.ml | 6 +- src/app/test_executive/snarkyjs.ml | 2 +- src/app/test_executive/test_common.ml | 26 +- .../test_executive/verification_key_update.ml | 8 +- src/app/test_executive/zkapps.ml | 46 +- src/app/test_executive/zkapps_nonce_test.ml | 10 +- src/app/test_executive/zkapps_timing.ml | 30 +- src/lib/integration_test_lib/dune | 13 +- .../integration_test_lib/graphql_requests.ml | 458 +++++++++++++++--- 12 files changed, 534 insertions(+), 187 deletions(-) diff --git a/src/app/test_executive/block_reward_test.ml b/src/app/test_executive/block_reward_test.ml index 851832d1428..5ba3b8e8ddd 100644 --- a/src/app/test_executive/block_reward_test.ml +++ b/src/app/test_executive/block_reward_test.ml @@ -52,7 +52,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "check that the account balances are what we expect after the block has \ been produced" (let%bind { total_balance = bp_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:bp_pk_account_id in (* TODO, the intg test framework is ignoring test_constants.coinbase_amount for whatever reason, so hardcoding this until that is fixed *) diff --git a/src/app/test_executive/dune b/src/app/test_executive/dune index 91a99540889..4b3e4b7a106 100644 --- a/src/app/test_executive/dune +++ b/src/app/test_executive/dune @@ -5,6 +5,7 @@ async_kernel async core + uri yojson core_kernel cmdliner diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 6badc3d9dfb..17a7d54d292 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -25,12 +25,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~vesting_increment : Mina_base.Account_timing.t = let open Currency in Timed - { initial_minimum_balance = Balance.of_int min_balance - ; cliff_time = Mina_numbers.Global_slot.of_int cliff_time - ; cliff_amount = Amount.of_int cliff_amount - ; vesting_period = Mina_numbers.Global_slot.of_int vesting_period - ; vesting_increment = Amount.of_int vesting_increment - } + { initial_minimum_balance = Balance.of_nanomina_int_exn min_balance + ; cliff_time = Mina_numbers.Global_slot_since_genesis.of_int cliff_time + ; cliff_amount = Amount.of_nanomina_int_exn cliff_amount + ; vesting_period = Mina_numbers.Global_slot_span.of_int vesting_period + ; vesting_increment = Amount.of_nanomina_int_exn vesting_increment + } in { default with requires_graphql = true @@ -106,8 +106,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in (* hardcoded values of the balances of fish1 (receiver) and fish2 (sender), update here if they change in the config *) (* TODO undo the harcoding, don't be lazy and just make the graphql commands to fetch the balances *) - let receiver_original_balance = Currency.Amount.of_formatted_string "100" in - let sender_original_balance = Currency.Amount.of_formatted_string "100" in + let receiver_original_balance = Currency.Amount.of_mina_string_exn "100" in + let sender_original_balance = Currency.Amount.of_mina_string_exn "100" in let sender = fish2.keypair in let receiver = fish1.keypair in [%log info] "extra genesis keypairs: %s" @@ -137,31 +137,31 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let receiver_pub_key = receiver.public_key |> Signature_lib.Public_key.compress in + let receiver_account_id = + Account_id.create receiver_pub_key Token_id.default + in let sender_pub_key = sender.public_key |> Signature_lib.Public_key.compress in + let sender_account_id = Account_id.create sender_pub_key Token_id.default in let%bind { nonce = sender_current_nonce; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) - ~public_key:sender_pub_key + ~account_id:sender_account_id in - let amount = Currency.Amount.of_formatted_string "10" in - let fee = Currency.Fee.of_formatted_string "1" in + let amount = Currency.Amount.of_mina_string_exn "10" in + let fee = Currency.Fee.of_mina_string_exn "1" in let memo = "" in - let token = Token_id.default in - let valid_until = Mina_numbers.Global_slot.max_value in + let valid_until = Mina_numbers.Global_slot_since_genesis.max_value in let payload = let payment_payload = { Payment_payload.Poly.receiver_pk = receiver_pub_key - ; source_pk = sender_pub_key - ; token_id = token ; amount } in let body = Signed_command_payload.Body.Payment payment_payload in let common = { Signed_command_payload.Common.Poly.fee - ; fee_token = Signed_command_payload.Body.token body ; fee_payer_pk = sender_pub_key ; nonce = sender_current_nonce ; valid_until @@ -181,11 +181,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_b) ~logger - ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~sender_pub_key:(Signed_command_payload.fee_payer_pk payload) ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) ~amount ~fee ~nonce:(Signed_command_payload.nonce payload) - ~memo ~token ~valid_until ~raw_signature + ~memo ~valid_until ~raw_signature in wait_for t (Wait_condition.signed_command_to_be_included_in_frontier @@ -198,12 +198,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind { total_balance = receiver_balance; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) - ~public_key:receiver_pub_key + ~account_id:receiver_account_id in let%bind { total_balance = sender_balance; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) - ~public_key:sender_pub_key + ~account_id:sender_account_id in (* TODO, the intg test framework is ignoring test_constants.coinbase_amount for whatever reason, so hardcoding this until that is fixed *) let receiver_expected = @@ -220,15 +220,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (* [%log info] "coinbase_amount: %s" (Currency.Amount.to_formatted_string coinbase_reward) ; *) [%log info] "txn_amount: %s" - (Currency.Amount.to_formatted_string amount) ; + (Currency.Amount.to_mina_string amount) ; [%log info] "receiver_expected: %s" - (Currency.Amount.to_formatted_string receiver_expected) ; + (Currency.Amount.to_mina_string receiver_expected) ; [%log info] "receiver_balance: %s" - (Currency.Balance.to_formatted_string receiver_balance) ; + (Currency.Balance.to_mina_string receiver_balance) ; [%log info] "sender_expected: %s" - (Currency.Amount.to_formatted_string sender_expected) ; + (Currency.Amount.to_mina_string sender_expected) ; [%log info] "sender_balance: %s" - (Currency.Balance.to_formatted_string sender_balance) ; + (Currency.Balance.to_mina_string sender_balance) ; if (* node_a is the receiver *) (* node_a_balance >= 400_000_000_000_000 + txn_amount *) @@ -249,11 +249,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "Error with account balances. receiver balance is %d and should \ be %d, sender balance is %d and should be %d. and txn_amount is \ %d" - (Currency.Balance.to_int receiver_balance) - (Currency.Amount.to_int receiver_expected) - (Currency.Balance.to_int sender_balance) - (Currency.Amount.to_int sender_expected) - (Currency.Amount.to_int amount) ) + (Currency.Balance.to_nanomina_int receiver_balance) + (Currency.Amount.to_nanomina_int receiver_expected) + (Currency.Balance.to_nanomina_int sender_balance) + (Currency.Amount.to_nanomina_int sender_expected) + (Currency.Amount.to_nanomina_int amount) ) in let%bind () = section @@ -264,11 +264,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_b) ~logger - ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~sender_pub_key:(Signed_command_payload.fee_payer_pk payload) ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) ~amount ~fee ~nonce:(Signed_command_payload.nonce payload) - ~memo ~token ~valid_until ~raw_signature + ~memo ~valid_until ~raw_signature with | Ok { nonce; _ } -> Malleable_error.soft_error_format ~value:() @@ -303,13 +303,13 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.send_payment_with_raw_sig (Network.Node.get_ingress_uri untimed_node_a) ~logger - ~sender_pub_key:(Signed_command_payload.source_pk payload) + ~sender_pub_key:(Signed_command_payload.fee_payer_pk payload) ~receiver_pub_key:(Signed_command_payload.receiver_pk payload) ~amount ~fee ~nonce: (Mina_numbers.Account_nonce.succ (Signed_command_payload.nonce payload) ) - ~memo ~token ~valid_until ~raw_signature + ~memo ~valid_until ~raw_signature with | Ok { nonce = returned_nonce; _ } -> Malleable_error.soft_error_format ~value:() @@ -336,7 +336,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "send a single payment from timed account using available liquid" - (let amount = Currency.Amount.of_int 1_000_000_000_000 in + (let amount = Currency.Amount.of_mina_int_exn 1_000 in let receiver = untimed_node_a in let%bind receiver_pub_key = pub_key_of_node receiver in let sender = timed_node_c in @@ -353,7 +353,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "unable to send payment from timed account using illiquid tokens" - (let amount = Currency.Amount.of_int 25_000_000_000_000 in + (let amount = Currency.Amount.of_mina_int_exn 25_000 in let receiver = untimed_node_b in let%bind receiver_pub_key = pub_key_of_node receiver in let sender = timed_node_c in @@ -361,14 +361,14 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind { total_balance = timed_node_c_total; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri timed_node_c) - ~public_key:sender_pub_key + ~account_id:sender_account_id in [%log info] "timed_node_c total balance: %s" - (Currency.Balance.to_formatted_string timed_node_c_total) ; + (Currency.Balance.to_mina_string timed_node_c_total) ; [%log info] "Attempting to send txn from timed_node_c to untimed_node_a for \ amount of %s" - (Currency.Amount.to_formatted_string amount) ; + (Currency.Amount.to_mina_string amount) ; (* TODO: refactor this using new [expect] dsl when it's available *) let open Deferred.Let_syntax in match%bind @@ -426,6 +426,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Wait_condition.ledger_proofs_emitted_since_genesis ~test_config:config ~num_proofs:1 ) ) in + let get_account_id pubk = (Account_id.create (pubk |> Signature_lib.Public_key.compress) Token_id.default) in let%bind () = section_hard "check account balances. snark-node-key1 should be greater than or \ @@ -433,19 +434,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind { total_balance = key_1_balance_actual; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) - ~public_key: - ( snark_node_key1.keypair.public_key - |> Signature_lib.Public_key.compress ) - in + ~account_id:(get_account_id snark_node_key1.keypair.public_key) + in let%bind { total_balance = key_2_balance_actual; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_a) - ~public_key: - ( snark_node_key2.keypair.public_key - |> Signature_lib.Public_key.compress ) - in + ~account_id:(get_account_id snark_node_key2.keypair.public_key ) + in let key_1_balance_expected = - Currency.Amount.of_formatted_string config.snark_worker_fee + Currency.Amount.of_mina_string_exn config.snark_worker_fee in if Currency.Amount.( >= ) @@ -457,8 +454,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct snark-node-key1 balance: %s. \n\ snark-node-key2 balance: %s. \n\ snark-worker-fee: %s" - (Currency.Balance.to_formatted_string key_1_balance_actual) - (Currency.Balance.to_formatted_string key_2_balance_actual) + (Currency.Balance.to_mina_string key_1_balance_actual) + (Currency.Balance.to_mina_string key_2_balance_actual) config.snark_worker_fee ; Malleable_error.return () ) @@ -468,8 +465,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct snark-node-key1 balance: %s. \n\ snark-node-key2 balance: %s. \n\ snark-worker-fee: %s" - (Currency.Balance.to_formatted_string key_1_balance_actual) - (Currency.Balance.to_formatted_string key_2_balance_actual) + (Currency.Balance.to_mina_string key_1_balance_actual) + (Currency.Balance.to_mina_string key_2_balance_actual) config.snark_worker_fee ) in let%bind () = @@ -508,19 +505,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind { total_balance = key_1_balance_actual; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) - ~public_key: - ( snark_node_key1.keypair.public_key - |> Signature_lib.Public_key.compress ) + ~account_id:(get_account_id snark_node_key1.keypair.public_key) in let%bind { total_balance = key_2_balance_actual; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_a) - ~public_key: - ( snark_node_key2.keypair.public_key - |> Signature_lib.Public_key.compress ) + ~account_id:(get_account_id snark_node_key2.keypair.public_key) in let key_2_balance_expected = - Currency.Amount.of_formatted_string config.snark_worker_fee + Currency.Amount.of_mina_string_exn config.snark_worker_fee in if Currency.Amount.( >= ) @@ -532,8 +525,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct snark-node-key1 balance: %s. \n\ snark-node-key2 balance: %s. \n\ snark-worker-fee: %s" - (Currency.Balance.to_formatted_string key_1_balance_actual) - (Currency.Balance.to_formatted_string key_2_balance_actual) + (Currency.Balance.to_mina_string key_1_balance_actual) + (Currency.Balance.to_mina_string key_2_balance_actual) config.snark_worker_fee ; Malleable_error.return () ) @@ -543,8 +536,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct snark-node-key1 balance: %s. \n\ snark-node-key2 balance: %s. \n\ snark-worker-fee: %s" - (Currency.Balance.to_formatted_string key_1_balance_actual) - (Currency.Balance.to_formatted_string key_2_balance_actual) + (Currency.Balance.to_mina_string key_1_balance_actual) + (Currency.Balance.to_mina_string key_2_balance_actual) config.snark_worker_fee ) in section_hard "running replayer" diff --git a/src/app/test_executive/peers_reliability_test.ml b/src/app/test_executive/peers_reliability_test.ml index b5db6d54b90..1128e044be5 100644 --- a/src/app/test_executive/peers_reliability_test.ml +++ b/src/app/test_executive/peers_reliability_test.ml @@ -90,7 +90,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind sender_pub_key = pub_key_of_node node_c in let%bind receiver_pub_key = pub_key_of_node node_b in let%bind { hash = txn_hash; _ } = - Node.must_send_payment ~logger node_c ~sender_pub_key + Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri node_c ) ~sender_pub_key ~receiver_pub_key ~amount:(Currency.Amount.of_nanomina_int_exn 1_000_000) ~fee:(Currency.Fee.of_nanomina_int_exn 10_000_000) @@ -140,7 +140,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~constraint_constants:(Network.constraint_constants network) parties_spec in - let%bind () = send_zkapp ~logger node_c parties_create_accounts in + let%bind () = send_zkapp ~logger (Network.Node.get_ingress_uri node_c) parties_create_accounts in wait_for_zkapp parties_create_accounts ) in let%bind () = @@ -152,7 +152,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Mina_base.Account_id.create pk Mina_base.Token_id.default in let%map _account_data = - Node.must_get_account_data ~logger node_c ~account_id + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node_c) ~account_id in () ) in diff --git a/src/app/test_executive/snarkyjs.ml b/src/app/test_executive/snarkyjs.ml index 178756e693e..70730d4c16d 100644 --- a/src/app/test_executive/snarkyjs.ml +++ b/src/app/test_executive/snarkyjs.ml @@ -45,7 +45,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Core.String.Map.find_exn (Network.block_producers network) "node" in let%bind fee_payer_key = priv_key_of_node node in - let graphql_uri = Network.Node.graphql_uri node in + let graphql_uri = Network.Node.get_ingress_uri node |> Uri.to_string in let%bind () = [%log info] "Waiting for nodes to be initialized" ; diff --git a/src/app/test_executive/test_common.ml b/src/app/test_executive/test_common.ml index 98c7a81e327..e4ace57c857 100644 --- a/src/app/test_executive/test_common.ml +++ b/src/app/test_executive/test_common.ml @@ -203,9 +203,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct | `Ok -> Malleable_error.return () - open Inputs.Engine - - let send_zkapp_batch ~logger node zkapp_commands = + let send_zkapp_batch ~logger node_uri zkapp_commands = List.iter zkapp_commands ~f:(fun zkapp_command -> [%log info] "Sending zkApp" ~metadata: @@ -216,7 +214,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct zkapp_command.memo ) ) ] ) ; match%bind.Deferred - Network.Node.send_zkapp_batch ~logger node ~zkapp_commands + Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri ~zkapp_commands with | Ok _zkapp_ids -> [%log info] "ZkApp transactions sent" ; @@ -231,10 +229,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let send_zkapp ~logger node zkapp_command = send_zkapp_batch ~logger node [ zkapp_command ] - let send_invalid_zkapp ~logger node zkapp_command substring = + let send_invalid_zkapp ~logger node_uri zkapp_command substring = [%log info] "Sending zkApp, expected to fail" ; match%bind.Deferred - Network.Node.send_zkapp_batch ~logger node + Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri ~zkapp_commands:[ zkapp_command ] with | Ok _zkapp_ids -> @@ -257,13 +255,13 @@ 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 + let send_invalid_payment ~logger node_uri ~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 + Integration_test_lib.Graphql_requests.send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature with | Ok _ -> @@ -285,11 +283,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Malleable_error.hard_error_format "Payment failed: %s, but expected \"%s\"" err_str expected_failure ) - let get_account_permissions ~logger node account_id = + let get_account_permissions ~logger node_uri 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 + Integration_test_lib.Graphql_requests.get_account_permissions ~logger node_uri ~account_id with | Ok permissions -> [%log info] "Got account permissions" ; @@ -300,11 +298,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~metadata:[ ("error", `String err_str) ] ; Malleable_error.hard_error (Error.of_string err_str) - let get_account_update ~logger node account_id = + let get_account_update ~logger node_uri 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 + Integration_test_lib.Graphql_requests.get_account_update ~logger node_uri ~account_id with | Ok update -> [%log info] "Got account update" ; @@ -315,12 +313,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~metadata:[ ("error", `String err_str) ] ; Malleable_error.hard_error (Error.of_string err_str) - let get_pooled_zkapp_commands ~logger node pk = + let get_pooled_zkapp_commands ~logger node_uri 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 + Integration_test_lib.Graphql_requests.get_pooled_zkapp_commands ~logger node_uri ~pk with | Ok zkapp_commands -> [%log info] "Got pooled zkApp commands" ; diff --git a/src/app/test_executive/verification_key_update.ml b/src/app/test_executive/verification_key_update.ml index cd8708f6fe8..322808a59b4 100644 --- a/src/app/test_executive/verification_key_update.ml +++ b/src/app/test_executive/verification_key_update.ml @@ -320,7 +320,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Send a zkApp to create a zkApp account" - (send_zkapp ~logger whale1 zkapp_command_create_account) + (send_zkapp ~logger (Network.Node.get_ingress_uri whale1) zkapp_command_create_account) in let%bind () = section @@ -331,21 +331,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" - (send_zkapp ~logger whale1 zkapp_command_update_vk1) + (send_zkapp ~logger (Network.Node.get_ingress_uri 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" - (send_invalid_zkapp ~logger whale1 zkapp_command_update_vk2_refers_vk1 + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri 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" - (send_zkapp ~logger whale1 zkapp_command_update_vk2) + (send_zkapp ~logger (Network.Node.get_ingress_uri 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 b456787b82d..4b3a625d015 100644 --- a/src/app/test_executive/zkapps.ml +++ b/src/app/test_executive/zkapps.ml @@ -77,7 +77,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind sender_pub_key = pub_key_of_node sender in let%bind receiver_pub_key = pub_key_of_node receiver in repeat_seq ~n ~f:(fun () -> - Network.Node.must_send_payment ~logger sender ~sender_pub_key + Integration_test_lib.Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri sender) ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee >>| ignore ) @@ -86,7 +86,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let send_payment_from_zkapp_account ?expected_failure ~(constraint_constants : Genesis_constants.Constraint_constants.t) ~logger - ~node (sender : Signature_lib.Keypair.t) nonce = + ~node_uri (sender : Signature_lib.Keypair.t) nonce = let sender_pk = Signature_lib.Public_key.compress sender.public_key in let receiver_pk = payment_receiver in let amount = @@ -116,12 +116,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct | Some failure -> send_invalid_payment ~logger ~sender_pub_key:sender_pk ~receiver_pub_key:receiver_pk ~amount ~fee ~nonce ~memo ~valid_until - ~raw_signature ~expected_failure:failure node + ~raw_signature ~expected_failure:failure node_uri | None -> incr transactions_sent ; - Network.Node.must_send_payment_with_raw_sig ~logger + Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig ~logger ~sender_pub_key:sender_pk ~receiver_pub_key:receiver_pk ~amount ~fee - ~nonce ~memo ~valid_until ~raw_signature node + ~nonce ~memo ~valid_until ~raw_signature node_uri |> Malleable_error.ignore_m let run network t = @@ -664,7 +664,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkApp transaction to create zkApp accounts" - (send_zkapp ~logger node zkapp_command_create_accounts) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_accounts) in let%bind () = section_hard @@ -676,12 +676,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = List.hd_exn zkapp_keypairs in let nonce = Account.Nonce.zero in section_hard "Send a valid payment from zkApp account" - (send_payment_from_zkapp_account ~constraint_constants ~node ~logger + (send_payment_from_zkapp_account ~constraint_constants ~node_uri:(Network.Node.get_ingress_uri node) ~logger sender nonce ) in let%bind () = section_hard "Send a zkApp transaction to update permissions" - (send_zkapp ~logger node zkapp_command_update_permissions) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_permissions) in let%bind () = section_hard @@ -694,7 +694,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let nonce = Account.Nonce.of_int 1 in section_hard "Send an invalid payment from zkApp account" (send_payment_from_zkapp_account ~constraint_constants ~logger sender - nonce ~node + nonce ~node_uri:(Network.Node.get_ingress_uri node) ~expected_failure: Network_pool.Transaction_pool.Diff_versioned.Diff_error.( to_string_name Fee_payer_not_permitted_to_send) ) @@ -705,7 +705,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 = - get_account_permissions ~logger node account_id + get_account_permissions ~logger (Network.Node.get_ingress_uri node) account_id in if Permissions.equal ledger_permissions permissions_updated then ( [%log info] "Ledger, updated permissions are equal" ; @@ -725,43 +725,43 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkapp with an insufficient fee" - (send_invalid_zkapp ~logger node zkapp_command_insufficient_fee + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_fee "Insufficient fee" ) in (* Won't be accepted until the previous transactions are applied *) let%bind () = section_hard "Send a zkApp transaction to update all fields" - (send_zkapp ~logger node zkapp_command_update_all) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_all) in let%bind () = section_hard "Send a zkapp with an invalid proof" - (send_invalid_zkapp ~logger node zkapp_command_invalid_proof + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_proof "Verification_failed" ) in let%bind () = section_hard "Send a zkapp with an insufficient replace fee" - (send_invalid_zkapp ~logger node zkapp_command_insufficient_replace_fee + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid nonce" - (send_invalid_zkapp ~logger node zkapp_command_invalid_nonce + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_nonce "Invalid_nonce" ) in let%bind () = section_hard "Send a zkApp transaction with insufficient_funds, fee too high" - (send_invalid_zkapp ~logger node zkapp_command_insufficient_funds + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_funds "Insufficient_funds" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid signature" - (send_invalid_zkapp ~logger node zkapp_command_invalid_signature + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_signature "Verification_failed" ) in let%bind () = section_hard "Send a zkApp transaction with a nonexistent fee payer" - (send_invalid_zkapp ~logger node zkapp_command_nonexistent_fee_payer + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_nonexistent_fee_payer "Fee_payer_account_not_found" ) in let%bind () = @@ -772,19 +772,19 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkApp transaction to mint token" - (send_zkapp ~logger node zkapp_command_mint_token) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_mint_token) in let%bind () = section_hard "Send a zkApp transaction to mint 2nd token" - (send_zkapp ~logger node zkapp_command_mint_token2) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_mint_token2) in let%bind () = section_hard "Send a zkApp transaction to transfer tokens" - (send_zkapp ~logger node zkapp_command_token_transfer) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_token_transfer) in let%bind () = section_hard "Send a zkApp transaction to transfer tokens (2)" - (send_zkapp ~logger node zkapp_command_token_transfer2) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_token_transfer2) in let%bind () = section_hard "Wait for zkApp transaction to mint token" @@ -808,7 +808,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 = - get_account_update ~logger node account_id + get_account_update ~logger (Network.Node.get_ingress_uri node) account_id in if compatible_updates ~ledger_update diff --git a/src/app/test_executive/zkapps_nonce_test.ml b/src/app/test_executive/zkapps_nonce_test.ml index 818ad7d6432..b6ea3dc1c33 100644 --- a/src/app/test_executive/zkapps_nonce_test.ml +++ b/src/app/test_executive/zkapps_nonce_test.ml @@ -83,7 +83,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind sender_pub_key = pub_key_of_node sender in let%bind receiver_pub_key = pub_key_of_node receiver in repeat_seq ~n ~f:(fun () -> - Network.Node.must_send_payment ~logger sender ~sender_pub_key + Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri sender) ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee >>| ignore ) @@ -279,7 +279,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Send a zkapp commands with fee payer nonce increments and nonce \ preconditions" - (send_zkapp_batch ~logger node + (send_zkapp_batch ~logger (Network.Node.get_ingress_uri node) [ invalid_nonce_zkapp_cmd_from_fish1; valid_zkapp_cmd_from_fish1 ] ) in let%bind () = @@ -298,7 +298,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 " - (send_zkapp_batch ~logger node + (send_zkapp_batch ~logger (Network.Node.get_ingress_uri node) [ set_permission_zkapp_cmd_from_fish1 ; valid_fee_invalid_permission_zkapp_cmd_from_fish1 ; invalid_fee_invalid_permission_zkapp_cmd_from_fish1 @@ -321,7 +321,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "Verify account update after the updated permission failed by checking \ account nonce" (let%bind { nonce = fish1_nonce; _ } = - Network.Node.get_account_data ~logger node + Graphql_requests.get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:fish1_account_id |> Deferred.bind ~f:Malleable_error.or_hard_error in @@ -339,7 +339,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Verify invalid zkapp commands are removed from transaction pool" (let%bind pooled_zkapp_commands = - Network.Node.get_pooled_zkapp_commands ~logger node ~pk:fish1_pk + Graphql_requests.get_pooled_zkapp_commands ~logger (Network.Node.get_ingress_uri node) ~pk:fish1_pk |> Deferred.bind ~f:Malleable_error.or_hard_error in [%log debug] "Pooled zkapp_commands $commands" diff --git a/src/app/test_executive/zkapps_timing.ml b/src/app/test_executive/zkapps_timing.ml index 0f7517dbaa4..2243b107bfe 100644 --- a/src/app/test_executive/zkapps_timing.ml +++ b/src/app/test_executive/zkapps_timing.ml @@ -372,7 +372,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp to create a zkApp account with timing" - (send_zkapp ~logger node zkapp_command_create_account_with_timing) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_account_with_timing) in let%bind () = section @@ -383,7 +383,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 2nd zkApp account with timing" - (send_zkapp ~logger node zkapp_command_create_second_account_with_timing) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_second_account_with_timing) in let%bind () = section @@ -394,7 +394,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 3rd zkApp account with timing" - (send_zkapp ~logger node zkapp_command_create_third_account_with_timing) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_third_account_with_timing) in let%bind () = section @@ -406,7 +406,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify zkApp timing in ledger" (let%bind ledger_update = - get_account_update ~logger node timing_account_id + get_account_update ~logger (Network.Node.get_ingress_uri node) timing_account_id in if compatible_updates ~ledger_update ~requested_update:timing_update then ( @@ -430,12 +430,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct incompatible" ) ) ) in let%bind { total_balance = before_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let%bind () = section "Send invalid zkApp with zero vesting period in timing" - (send_invalid_zkapp ~logger node zkapp_command_with_zero_vesting_period + (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_with_zero_vesting_period "Zero vesting period" ) in (* let%bind before_balance = @@ -443,7 +443,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in *) let%bind () = section "Send a zkApp with transfer from timed account that succeeds" - (send_zkapp ~logger node zkapp_command_transfer_from_timed_account) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_transfer_from_timed_account) in let%bind () = section "Waiting for zkApp with transfer from timed account that succeeds" @@ -454,7 +454,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct get_account_balance ~logger node timing_account_id in *) let%bind { total_balance = after_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let%bind () = @@ -506,7 +506,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct use all the liquid after 1 slot. *) let%bind { liquid_balance_opt = before_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:third_timed_account_id in let before_balance_int = @@ -564,7 +564,7 @@ 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" - (send_zkapp ~logger node zkapp_command_transfer_from_third_timed_account) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_transfer_from_third_timed_account) in let%bind () = section @@ -608,7 +608,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct failwith "Amount to debit more than timed account balance" in let%bind { locked_balance_opt = locked_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in (* let%bind locked_balance = @@ -618,7 +618,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct assert ( Currency.Amount.( < ) proposed_balance (Option.value_exn locked_balance |> Currency.Balance.to_amount) ) ; - send_zkapp ~logger node + send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_transfer_from_timed_account ) in let%bind () = @@ -637,7 +637,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct get_account_balance ~logger node timing_account_id in *) (let%bind { total_balance = after_invalid_balance; _ } = - Network.Node.must_get_account_data ~logger node + Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let after_invalid_balance_as_amount = @@ -668,7 +668,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp with invalid timing update" - (send_zkapp ~logger node zkapp_command_update_timing) + (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_timing) in let%bind () = section "Wait for snapp with invalid timing update" @@ -677,7 +677,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify timing has not changed" (let%bind ledger_update = - get_account_update ~logger node timing_account_id + get_account_update ~logger (Network.Node.get_ingress_uri node) timing_account_id in if compatible_item ledger_update.timing timing_update.timing diff --git a/src/lib/integration_test_lib/dune b/src/lib/integration_test_lib/dune index 87830d7e351..c64ee81db83 100644 --- a/src/lib/integration_test_lib/dune +++ b/src/lib/integration_test_lib/dune @@ -3,9 +3,12 @@ (name integration_test_lib) (inline_tests) (instrumentation (backend bisect_ppx)) -; (preprocessor_deps ../../graphql-ppx-config.inc ../../../graphql_schema.json) - - (preprocess (pps ppx_base ppx_fields_conv ppx_mina ppx_version ppx_optcomp ppx_let ppx_inline_test ppx_custom_printf ppx_deriving.std ppx_sexp_conv ppx_compare ppx_assert lens.ppx_deriving ppx_pipebang graphql_ppx -- %{read-lines:../../graphql-ppx-config.inc})) + (preprocessor_deps ../../graphql-ppx-config.inc ../../../graphql_schema.json) + (preprocess (pps + ppx_base ppx_fields_conv ppx_mina ppx_version ppx_let + ppx_inline_test ppx_custom_printf ppx_deriving.std ppx_sexp_conv ppx_compare + ppx_assert lens.ppx_deriving ppx_pipebang + graphql_ppx -- %{read-lines:../../graphql-ppx-config.inc})) (libraries ;; opam libraries result @@ -47,7 +50,11 @@ mina_base.import mina_numbers mina_transaction + pickles + pickles_types + with_hash data_hash_lib + generated_graphql_queries mina_graphql graphql_lib integers diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index ec91d6619dc..bfb2f5066f3 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -1,6 +1,11 @@ open Core_kernel open Async open Mina_base +open Mina_transaction + + +(* exclude from bisect_ppx to avoid type error on GraphQL modules *) +[@@@coverage exclude_file] let node_password = "naughty blue worm" @@ -118,6 +123,10 @@ module Graphql = struct } |}] + (* TODO: temporary version *) + module Send_test_zkapp = Generated_graphql_queries.Send_test_zkapp + module Pooled_zkapp_commands = Generated_graphql_queries.Pooled_zkapp_commands + module Query_peer_id = [%graphql {| @@ -139,7 +148,7 @@ module Graphql = struct {| query ($max_length: Int) @encoders(module: "Encoders"){ bestChain (maxLength: $max_length) { - stateHash + stateHash @ppxCustom(module: "Graphql_lib.Scalars.String_json") commandTransactionCount creatorAccount { publicKey @ppxCustom(module: "Graphql_lib.Scalars.JSON") @@ -182,6 +191,50 @@ module Graphql = struct } } |}] + + module Account = + [%graphql + {| + query ($public_key: PublicKey!, $token: UInt64) { + account (publicKey : $public_key, token : $token) { + balance { liquid + locked + total + } + delegate + nonce + permissions { editActionState + editState + incrementNonce + receive + send + access + setDelegate + setPermissions + setZkappUri + setTokenSymbol + setVerificationKey + setVotingFor + setTiming + } + actionState + zkappState + zkappUri + timing { cliffTime @ppxCustom(module: "Graphql_lib.Scalars.JSON") + cliffAmount + vestingPeriod @ppxCustom(module: "Graphql_lib.Scalars.JSON") + vestingIncrement + initialMinimumBalance + } + tokenId + tokenSymbol + verificationKey { verificationKey + hash + } + votingFor + } + } + |}] end (* this function will repeatedly attempt to connect to graphql port times before giving up *) @@ -287,49 +340,263 @@ let must_get_best_chain ?max_length ~logger node_uri = get_best_chain ?max_length ~logger node_uri |> Deferred.bind ~f:Malleable_error.or_hard_error +let get_account ~logger node_uri ~account_id = + let pk = Mina_base.Account_id.public_key account_id in + let token = Mina_base.Account_id.token_id account_id in + [%log info] "Getting account" + ~metadata:[ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pk) ] ; + let get_account_obj = + Graphql.Account.( + make + @@ makeVariables + ~public_key:(Graphql_lib.Encoders.public_key pk) + ~token:(Graphql_lib.Encoders.token token) + ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"get_account_graphql" + get_account_obj + type account_data = - { nonce : Unsigned.uint32; total_balance : Currency.Balance.t } + { nonce : Mina_numbers.Account_nonce.t + ; total_balance : Currency.Balance.t + ; liquid_balance_opt : Currency.Balance.t option + ; locked_balance_opt : Currency.Balance.t option + } -let get_account_data ~logger node_uri ~public_key = +let get_account_data ~logger node_uri ~account_id = let open Deferred.Or_error.Let_syntax in - [%log info] "Getting account balance" + let public_key = Mina_base.Account_id.public_key account_id in + let token = Mina_base.Account_id.token_id account_id in + [%log info] "Getting account data, which is its balances and nonce" ~metadata: - [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key) - ; ("node_uri", `String (Uri.to_string node_uri)) - ] ; - (* let pk = Mina_base.Account_id.public_key account_id in *) - (* let token = Mina_base.Account_id.token_id account_id in *) - let get_balance_obj = - Graphql.Get_account_data.( - make - @@ makeVariables ~public_key - (* ~token:(Graphql_lib.Encoders.token token) *) - ()) - in - let%bind balance_obj = - exec_graphql_request ~logger ~node_uri ~query_name:"get_balance_graphql" - get_balance_obj - in - match balance_obj.account with + [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key) ] ; + let%bind account_obj = get_account ~logger node_uri ~account_id in + match account_obj.account with | None -> Deferred.Or_error.errorf - !"Account with public_key %s not found" + !"Account with Account id %{sexp:Mina_base.Account_id.t}, public_key \ + %s, and token %s not found" + account_id (Signature_lib.Public_key.Compressed.to_string public_key) + (Mina_base.Token_id.to_string token) | Some acc -> return { nonce = - acc.nonce - |> Option.value_exn ~message:"the nonce from get_balance is None" - |> Unsigned.UInt32.of_string + Option.value_exn + ~message: + "the nonce from get_balance is None, which should be impossible" + acc.nonce ; total_balance = acc.balance.total + ; liquid_balance_opt = acc.balance.liquid + ; locked_balance_opt = acc.balance.locked } -let must_get_account_data ~logger node_uri ~public_key = - get_account_data ~logger node_uri ~public_key +let must_get_account_data ~logger node_uri ~account_id = + get_account_data ~logger node_uri ~account_id |> Deferred.bind ~f:Malleable_error.or_hard_error + + let permissions_of_account_permissions account_permissions : + Mina_base.Permissions.t = + (* the polymorphic variants come from Partial_accounts.auth_required in Mina_graphql *) + let to_auth_required = function + | `Either -> + Mina_base.Permissions.Auth_required.Either + | `Impossible -> + Impossible + | `None -> + None + | `Proof -> + Proof + | `Signature -> + Signature + in + let open Graphql.Account in + { edit_action_state = to_auth_required account_permissions.editActionState + ; edit_state = to_auth_required account_permissions.editState + ; increment_nonce = to_auth_required account_permissions.incrementNonce + ; receive = to_auth_required account_permissions.receive + ; send = to_auth_required account_permissions.send + ; access = to_auth_required account_permissions.access + ; set_delegate = to_auth_required account_permissions.setDelegate + ; set_permissions = to_auth_required account_permissions.setPermissions + ; set_zkapp_uri = to_auth_required account_permissions.setZkappUri + ; set_token_symbol = to_auth_required account_permissions.setTokenSymbol + ; set_verification_key = + to_auth_required account_permissions.setVerificationKey + ; set_voting_for = to_auth_required account_permissions.setVotingFor + ; set_timing = to_auth_required account_permissions.setTiming + } + + + let get_account_permissions ~logger t ~account_id = + let open Deferred.Or_error in + let open Let_syntax in + let%bind account_obj = get_account ~logger t ~account_id in + match account_obj.account with + | Some account -> ( + match account.permissions with + | Some ledger_permissions -> + return @@ permissions_of_account_permissions ledger_permissions + | None -> + fail + (Error.of_string "Could not get permissions from ledger account") + ) + | None -> + fail (Error.of_string "Could not get account from ledger") + + (* return a Account_update.Update.t with all fields `Set` to the + value in the account, or `Keep` if value unavailable, + as if this update had been applied to the account + *) + let get_account_update ~logger t ~account_id = + let open Deferred.Or_error in + let open Let_syntax in + let%bind account_obj = get_account ~logger t ~account_id in + match account_obj.account with + | Some account -> + let open Mina_base.Zkapp_basic.Set_or_keep in + let%bind app_state = + match account.zkappState with + | Some strs -> + let fields = + Array.to_list strs |> Base.List.map ~f:(fun s -> Set s) + in + return (Mina_base.Zkapp_state.V.of_list_exn fields) + | None -> + fail + (Error.of_string + (sprintf + "Expected zkApp account with an app state for public key \ + %s" + (Signature_lib.Public_key.Compressed.to_base58_check + (Mina_base.Account_id.public_key account_id) ) ) ) + in + let%bind delegate = + match account.delegate with + | Some s -> + return (Set s) + | None -> + fail (Error.of_string "Expected delegate in account") + in + let%bind verification_key = + match account.verificationKey with + | Some vk_obj -> + let data = vk_obj.verificationKey in + let hash = vk_obj.hash in + return (Set ({ data; hash } : _ With_hash.t)) + | None -> + fail + (Error.of_string + (sprintf + "Expected zkApp account with a verification key for \ + public_key %s" + (Signature_lib.Public_key.Compressed.to_base58_check + (Mina_base.Account_id.public_key account_id) ) ) ) + in + let%bind permissions = + match account.permissions with + | Some perms -> + return @@ Set (permissions_of_account_permissions perms) + | None -> + fail (Error.of_string "Expected permissions in account") + in + let%bind zkapp_uri = + match account.zkappUri with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected zkApp URI in account") + in + let%bind token_symbol = + match account.tokenSymbol with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected token symbol in account") + in + let%bind timing = + let timing = account.timing in + let cliff_amount = timing.cliffAmount in + let cliff_time = timing.cliffTime in + let vesting_period = timing.vestingPeriod in + let vesting_increment = timing.vestingIncrement in + let initial_minimum_balance = timing.initialMinimumBalance in + match + ( cliff_amount + , cliff_time + , vesting_period + , vesting_increment + , initial_minimum_balance ) + with + | None, None, None, None, None -> + return @@ Keep + | Some amt, Some tm, Some period, Some incr, Some bal -> + let cliff_amount = amt in + let%bind cliff_time = + match tm with + | `String s -> + return @@ Mina_numbers.Global_slot_since_genesis.of_string s + | _ -> + fail + (Error.of_string + "Expected string for cliff time in account timing" ) + in + let%bind vesting_period = + match period with + | `String s -> + return @@ Mina_numbers.Global_slot_span.of_string s + | _ -> + fail + (Error.of_string + "Expected string for vesting period in account timing" ) + in + let vesting_increment = incr in + let initial_minimum_balance = bal in + return + (Set + ( { initial_minimum_balance + ; cliff_amount + ; cliff_time + ; vesting_period + ; vesting_increment + } + : Mina_base.Account_update.Update.Timing_info.t ) ) + | _ -> + fail (Error.of_string "Some pieces of account timing are missing") + in + let%bind voting_for = + match account.votingFor with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected voting-for state hash in account") + in + return + ( { app_state + ; delegate + ; verification_key + ; permissions + ; zkapp_uri + ; token_symbol + ; timing + ; voting_for + } + : Mina_base.Account_update.Update.t ) + | None -> + fail (Error.of_string "Could not get account from ledger") + + + + type signed_command_result = - { id : string; hash : Transaction_hash.t; nonce : Unsigned.uint32 } + { id : string + ; hash : Transaction_hash.t + ; nonce : Mina_numbers.Account_nonce.t + } + +let transaction_id_to_string id = + Yojson.Basic.to_string (Graphql_lib.Scalars.TransactionId.serialize id) (* if we expect failure, might want retry_on_graphql_error to be false *) let send_online_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key @@ -370,16 +637,16 @@ let send_online_payment ~logger node_uri ~sender_pub_key ~receiver_pub_key let%map sent_payment_obj = send_payment_graphql () in let return_obj = sent_payment_obj.sendPayment.payment in let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce + { id = transaction_id_to_string return_obj.id + ; hash = return_obj.hash + ; nonce = Mina_numbers.Account_nonce.of_int return_obj.nonce } in [%log info] "Sent payment" ~metadata: [ ("user_command_id", `String res.id) ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ; ("nonce", `Int (Mina_numbers.Account_nonce.to_int res.nonce)) ] ; res @@ -388,6 +655,86 @@ let must_send_online_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount send_online_payment ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee |> Deferred.bind ~f:Malleable_error.or_hard_error +let send_zkapp_batch ~logger node_uri + ~(zkapp_commands : Mina_base.Zkapp_command.t list) = + [%log info] "Sending zkapp transactions" + ~metadata:[ ("node_uri", `String (Uri.to_string node_uri)) ] ; + let open Deferred.Or_error.Let_syntax in + let zkapp_commands_json = + List.map zkapp_commands ~f:(fun zkapp_command -> + Mina_base.Zkapp_command.to_json zkapp_command |> Yojson.Safe.to_basic ) + |> Array.of_list + in + let send_zkapp_graphql () = + let send_zkapp_obj = + Graphql.Send_test_zkapp.( + make @@ makeVariables ~zkapp_commands:zkapp_commands_json ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"send_zkapp_graphql" + send_zkapp_obj + in + let%bind sent_zkapp_obj = send_zkapp_graphql () in + let%bind zkapp_ids = + Deferred.Array.fold ~init:(Ok []) sent_zkapp_obj.internalSendZkapp + ~f:(fun acc (zkapp_obj : Graphql.Send_test_zkapp.t_internalSendZkapp) -> + let%bind res = + match zkapp_obj.zkapp.failureReason with + | None -> + let zkapp_id = transaction_id_to_string zkapp_obj.zkapp.id in + [%log info] "Sent zkapp transaction" + ~metadata:[ ("zkapp_id", `String zkapp_id) ] ; + return zkapp_id + | Some s -> + Deferred.Or_error.errorf "Zkapp failed, reason: %s" + ( Array.fold ~init:[] s ~f:(fun acc f -> + match f with + | None -> + acc + | Some f -> + let t = + ( Option.value_exn f.index + , f.failures |> Array.to_list |> List.rev ) + in + t :: acc ) + |> Mina_base.Transaction_status.Failure.Collection.Display + .to_yojson |> Yojson.Safe.to_string ) + in + let%map acc = Deferred.return acc in + res :: acc ) + in + return (List.rev zkapp_ids) + +let get_pooled_zkapp_commands ~logger node_uri + ~(pk : Signature_lib.Public_key.Compressed.t) = + [%log info] "Retrieving zkapp_commands from transaction pool" + ~metadata: + [ ("node_uri", `String (Uri.to_string node_uri)) + ; ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pk) + ] ; + let open Deferred.Or_error.Let_syntax in + let get_pooled_zkapp_commands_graphql () = + let get_pooled_zkapp_commands = + Graphql.Pooled_zkapp_commands.( + make + @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) + in + exec_graphql_request ~logger ~node_uri ~query_name:"get_pooled_zkapp_commands" + get_pooled_zkapp_commands + in + let%bind zkapp_pool_obj = get_pooled_zkapp_commands_graphql () in + let transaction_ids = + Array.map zkapp_pool_obj.pooledZkappCommands ~f:(fun zkapp_command -> + zkapp_command.id |> Transaction_id.to_base64 ) + |> Array.to_list + in + [%log info] "Retrieved zkapp_commands from transaction pool" + ~metadata: + [ ("node_uri", `String (Uri.to_string node_uri)) + ; ( "transaction ids" + , `List (List.map ~f:(fun t -> `String t) transaction_ids) ) + ] ; + return transaction_ids + let send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee = [%log info] "Sending stake delegation" ~metadata: @@ -426,16 +773,16 @@ let send_delegation ~logger node_uri ~sender_pub_key ~receiver_pub_key ~fee = let%map result_obj = send_delegation_graphql () in let return_obj = result_obj.sendDelegation.delegation in let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce + { id = transaction_id_to_string return_obj.id + ; hash = return_obj.hash + ; nonce = Mina_numbers.Account_nonce.of_int return_obj.nonce } in [%log info] "stake delegation sent" ~metadata: [ ("user_command_id", `String res.id) ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ; ("nonce", `Int (Mina_numbers.Account_nonce.to_int res.nonce)) ] ; res @@ -445,7 +792,8 @@ let must_send_delegation ~logger node_uri ~sender_pub_key |> Deferred.bind ~f:Malleable_error.or_hard_error let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature = + ~amount ~fee ~nonce ~memo + ~(valid_until : Mina_numbers.Global_slot_since_genesis.t) ~raw_signature = [%log info] "Sending a payment with raw signature" ~metadata: [ ( "sender_pub_key" @@ -457,7 +805,10 @@ let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key let open Graphql.Send_payment_with_raw_sig in let input = Mina_graphql.Types.Input.SendPaymentInput.make_input ~from:sender_pub_key - ~to_:receiver_pub_key ~amount ~token ~fee ~memo ~nonce ~valid_until () + ~to_:receiver_pub_key ~amount ~fee ~memo ~nonce + ~valid_until: + (Mina_numbers.Global_slot_since_genesis.to_uint32 valid_until) + () in let variables = makeVariables ~input ~rawSignature:raw_signature () in let send_payment_obj = make variables in @@ -474,44 +825,41 @@ let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key let%map sent_payment_obj = send_payment_graphql () in let return_obj = sent_payment_obj.sendPayment.payment in let res = - { id = return_obj.id - ; hash = Transaction_hash.of_base58_check_exn return_obj.hash - ; nonce = Unsigned.UInt32.of_int return_obj.nonce + { id = transaction_id_to_string return_obj.id + ; hash = return_obj.hash + ; nonce = Mina_numbers.Account_nonce.of_int return_obj.nonce } in [%log info] "Sent payment" ~metadata: [ ("user_command_id", `String res.id) ; ("hash", `String (Transaction_hash.to_base58_check res.hash)) - ; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce)) + ; ("nonce", `Int (Mina_numbers.Account_nonce.to_int res.nonce)) ] ; res let must_send_payment_with_raw_sig ~logger node_uri ~sender_pub_key - ~receiver_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until - ~raw_signature = + ~receiver_pub_key ~amount ~fee ~nonce ~memo + ~(valid_until : Mina_numbers.Global_slot_since_genesis.t) ~raw_signature = send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature + ~amount ~fee ~nonce ~memo + ~(valid_until : Mina_numbers.Global_slot_since_genesis.t) + ~raw_signature |> Deferred.bind ~f:Malleable_error.or_hard_error let sign_and_send_payment ~logger node_uri ~(sender_keypair : Import.Signature_keypair.t) ~receiver_pub_key ~amount - ~fee ~nonce ~memo ~token ~valid_until = + ~fee ~nonce ~memo ~valid_until = let sender_pub_key = sender_keypair.public_key |> Signature_lib.Public_key.compress in let payload = let body = Signed_command_payload.Body.Payment - { Payment_payload.Poly.receiver_pk = receiver_pub_key - ; source_pk = sender_pub_key - ; token_id = token - ; amount - } + { Payment_payload.Poly.receiver_pk = receiver_pub_key; amount } in let common = { Signed_command_payload.Common.Poly.fee - ; fee_token = Signed_command_payload.Body.token body ; fee_payer_pk = sender_pub_key ; nonce ; valid_until @@ -525,14 +873,14 @@ let sign_and_send_payment ~logger node_uri |> Signature.Raw.encode in send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key - ~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature + ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature let must_sign_and_send_payment ~logger node_uri ~(sender_keypair : Import.Signature_keypair.t) ~receiver_pub_key ~amount - ~fee ~nonce ~memo ~token ~valid_until = + ~fee ~nonce ~memo ~valid_until = sign_and_send_payment ~logger node_uri ~(sender_keypair : Import.Signature_keypair.t) - ~receiver_pub_key ~amount ~fee ~nonce ~memo ~token ~valid_until + ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until |> Deferred.bind ~f:Malleable_error.or_hard_error let send_test_payments ~(repeat_count : Unsigned.UInt32.t) From a6869145b552d3d13782090f8d2961dba8b566e3 Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Wed, 28 Jun 2023 16:19:36 +0200 Subject: [PATCH 14/15] oop gotta ocaml format --- src/app/test_executive/block_reward_test.ml | 3 +- src/app/test_executive/payments_test.ml | 31 +- .../test_executive/peers_reliability_test.ml | 15 +- src/app/test_executive/test_common.ml | 19 +- .../test_executive/verification_key_update.ml | 17 +- src/app/test_executive/zkapps.ml | 90 +++-- src/app/test_executive/zkapps_nonce_test.ml | 18 +- src/app/test_executive/zkapps_timing.ml | 55 ++- .../integration_test_lib/graphql_requests.ml | 380 +++++++++--------- 9 files changed, 349 insertions(+), 279 deletions(-) diff --git a/src/app/test_executive/block_reward_test.ml b/src/app/test_executive/block_reward_test.ml index 5ba3b8e8ddd..cf30894453e 100644 --- a/src/app/test_executive/block_reward_test.ml +++ b/src/app/test_executive/block_reward_test.ml @@ -52,7 +52,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "check that the account balances are what we expect after the block has \ been produced" (let%bind { total_balance = bp_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:bp_pk_account_id in (* TODO, the intg test framework is ignoring test_constants.coinbase_amount for whatever reason, so hardcoding this until that is fixed *) diff --git a/src/app/test_executive/payments_test.ml b/src/app/test_executive/payments_test.ml index 17a7d54d292..f8c1777873f 100644 --- a/src/app/test_executive/payments_test.ml +++ b/src/app/test_executive/payments_test.ml @@ -25,12 +25,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~vesting_increment : Mina_base.Account_timing.t = let open Currency in Timed - { initial_minimum_balance = Balance.of_nanomina_int_exn min_balance - ; cliff_time = Mina_numbers.Global_slot_since_genesis.of_int cliff_time - ; cliff_amount = Amount.of_nanomina_int_exn cliff_amount - ; vesting_period = Mina_numbers.Global_slot_span.of_int vesting_period - ; vesting_increment = Amount.of_nanomina_int_exn vesting_increment - } + { initial_minimum_balance = Balance.of_nanomina_int_exn min_balance + ; cliff_time = Mina_numbers.Global_slot_since_genesis.of_int cliff_time + ; cliff_amount = Amount.of_nanomina_int_exn cliff_amount + ; vesting_period = Mina_numbers.Global_slot_span.of_int vesting_period + ; vesting_increment = Amount.of_nanomina_int_exn vesting_increment + } in { default with requires_graphql = true @@ -155,9 +155,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let valid_until = Mina_numbers.Global_slot_since_genesis.max_value in let payload = let payment_payload = - { Payment_payload.Poly.receiver_pk = receiver_pub_key - ; amount - } + { Payment_payload.Poly.receiver_pk = receiver_pub_key; amount } in let body = Signed_command_payload.Body.Payment payment_payload in let common = @@ -219,8 +217,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in (* [%log info] "coinbase_amount: %s" (Currency.Amount.to_formatted_string coinbase_reward) ; *) - [%log info] "txn_amount: %s" - (Currency.Amount.to_mina_string amount) ; + [%log info] "txn_amount: %s" (Currency.Amount.to_mina_string amount) ; [%log info] "receiver_expected: %s" (Currency.Amount.to_mina_string receiver_expected) ; [%log info] "receiver_balance: %s" @@ -426,7 +423,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Wait_condition.ledger_proofs_emitted_since_genesis ~test_config:config ~num_proofs:1 ) ) in - let get_account_id pubk = (Account_id.create (pubk |> Signature_lib.Public_key.compress) Token_id.default) in + let get_account_id pubk = + Account_id.create + (pubk |> Signature_lib.Public_key.compress) + Token_id.default + in let%bind () = section_hard "check account balances. snark-node-key1 should be greater than or \ @@ -435,12 +436,12 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_b) ~account_id:(get_account_id snark_node_key1.keypair.public_key) - in + in let%bind { total_balance = key_2_balance_actual; _ } = Integration_test_lib.Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri untimed_node_a) - ~account_id:(get_account_id snark_node_key2.keypair.public_key ) - in + ~account_id:(get_account_id snark_node_key2.keypair.public_key) + in let key_1_balance_expected = Currency.Amount.of_mina_string_exn config.snark_worker_fee in diff --git a/src/app/test_executive/peers_reliability_test.ml b/src/app/test_executive/peers_reliability_test.ml index 1128e044be5..253358f3821 100644 --- a/src/app/test_executive/peers_reliability_test.ml +++ b/src/app/test_executive/peers_reliability_test.ml @@ -90,8 +90,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (let%bind sender_pub_key = pub_key_of_node node_c in let%bind receiver_pub_key = pub_key_of_node node_b in let%bind { hash = txn_hash; _ } = - Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri node_c ) ~sender_pub_key - ~receiver_pub_key + Graphql_requests.must_send_online_payment ~logger + (Network.Node.get_ingress_uri node_c) + ~sender_pub_key ~receiver_pub_key ~amount:(Currency.Amount.of_nanomina_int_exn 1_000_000) ~fee:(Currency.Fee.of_nanomina_int_exn 10_000_000) in @@ -140,7 +141,11 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~constraint_constants:(Network.constraint_constants network) parties_spec in - let%bind () = send_zkapp ~logger (Network.Node.get_ingress_uri node_c) parties_create_accounts in + let%bind () = + send_zkapp ~logger + (Network.Node.get_ingress_uri node_c) + parties_create_accounts + in wait_for_zkapp parties_create_accounts ) in let%bind () = @@ -152,7 +157,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Mina_base.Account_id.create pk Mina_base.Token_id.default in let%map _account_data = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node_c) ~account_id + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node_c) + ~account_id in () ) in diff --git a/src/app/test_executive/test_common.ml b/src/app/test_executive/test_common.ml index e4ace57c857..2d006209c2a 100644 --- a/src/app/test_executive/test_common.ml +++ b/src/app/test_executive/test_common.ml @@ -214,7 +214,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct zkapp_command.memo ) ) ] ) ; match%bind.Deferred - Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri ~zkapp_commands + Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri + ~zkapp_commands with | Ok _zkapp_ids -> [%log info] "ZkApp transactions sent" ; @@ -232,7 +233,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let send_invalid_zkapp ~logger node_uri zkapp_command substring = [%log info] "Sending zkApp, expected to fail" ; match%bind.Deferred - Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri + Integration_test_lib.Graphql_requests.send_zkapp_batch ~logger node_uri ~zkapp_commands:[ zkapp_command ] with | Ok _zkapp_ids -> @@ -261,8 +262,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct [%log info] "Sending payment, expected to fail" ; let expected_failure = String.lowercase expected_failure in match%bind.Deferred - Integration_test_lib.Graphql_requests.send_payment_with_raw_sig ~logger node_uri ~sender_pub_key - ~receiver_pub_key ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature + Integration_test_lib.Graphql_requests.send_payment_with_raw_sig ~logger + node_uri ~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 ; @@ -287,7 +289,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct [%log info] "Getting permissions for account" ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; match%bind.Deferred - Integration_test_lib.Graphql_requests.get_account_permissions ~logger node_uri ~account_id + Integration_test_lib.Graphql_requests.get_account_permissions ~logger + node_uri ~account_id with | Ok permissions -> [%log info] "Got account permissions" ; @@ -302,7 +305,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct [%log info] "Getting update for account" ~metadata:[ ("account_id", Mina_base.Account_id.to_yojson account_id) ] ; match%bind.Deferred - Integration_test_lib.Graphql_requests.get_account_update ~logger node_uri ~account_id + Integration_test_lib.Graphql_requests.get_account_update ~logger node_uri + ~account_id with | Ok update -> [%log info] "Got account update" ; @@ -318,7 +322,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~metadata: [ ("pub_key", Signature_lib.Public_key.Compressed.to_yojson pk) ] ; match%bind.Deferred - Integration_test_lib.Graphql_requests.get_pooled_zkapp_commands ~logger node_uri ~pk + Integration_test_lib.Graphql_requests.get_pooled_zkapp_commands ~logger + node_uri ~pk with | Ok zkapp_commands -> [%log info] "Got pooled zkApp commands" ; diff --git a/src/app/test_executive/verification_key_update.ml b/src/app/test_executive/verification_key_update.ml index 322808a59b4..cc57c9cb62b 100644 --- a/src/app/test_executive/verification_key_update.ml +++ b/src/app/test_executive/verification_key_update.ml @@ -320,7 +320,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Send a zkApp to create a zkApp account" - (send_zkapp ~logger (Network.Node.get_ingress_uri whale1) zkapp_command_create_account) + (send_zkapp ~logger + (Network.Node.get_ingress_uri whale1) + zkapp_command_create_account ) in let%bind () = section @@ -331,21 +333,26 @@ 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" - (send_zkapp ~logger (Network.Node.get_ingress_uri whale1) zkapp_command_update_vk1) + (send_zkapp ~logger + (Network.Node.get_ingress_uri 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" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri whale1) zkapp_command_update_vk2_refers_vk1 - "Verification_failed" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri 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" - (send_zkapp ~logger (Network.Node.get_ingress_uri whale1) zkapp_command_update_vk2) + (send_zkapp ~logger + (Network.Node.get_ingress_uri 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 4b3a625d015..d92f2f14647 100644 --- a/src/app/test_executive/zkapps.ml +++ b/src/app/test_executive/zkapps.ml @@ -77,8 +77,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind sender_pub_key = pub_key_of_node sender in let%bind receiver_pub_key = pub_key_of_node receiver in repeat_seq ~n ~f:(fun () -> - Integration_test_lib.Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri sender) ~sender_pub_key - ~receiver_pub_key ~amount:Currency.Amount.one ~fee + Integration_test_lib.Graphql_requests.must_send_online_payment ~logger + (Network.Node.get_ingress_uri sender) + ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee >>| ignore ) let payment_receiver = @@ -119,9 +120,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct ~raw_signature ~expected_failure:failure node_uri | None -> incr transactions_sent ; - Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig ~logger - ~sender_pub_key:sender_pk ~receiver_pub_key:receiver_pk ~amount ~fee - ~nonce ~memo ~valid_until ~raw_signature node_uri + Integration_test_lib.Graphql_requests.must_send_payment_with_raw_sig + ~logger ~sender_pub_key:sender_pk ~receiver_pub_key:receiver_pk + ~amount ~fee ~nonce ~memo ~valid_until ~raw_signature node_uri |> Malleable_error.ignore_m let run network t = @@ -664,7 +665,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkApp transaction to create zkApp accounts" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_accounts) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_create_accounts ) in let%bind () = section_hard @@ -676,12 +679,15 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let sender = List.hd_exn zkapp_keypairs in let nonce = Account.Nonce.zero in section_hard "Send a valid payment from zkApp account" - (send_payment_from_zkapp_account ~constraint_constants ~node_uri:(Network.Node.get_ingress_uri node) ~logger - sender nonce ) + (send_payment_from_zkapp_account ~constraint_constants + ~node_uri:(Network.Node.get_ingress_uri node) + ~logger sender nonce ) in let%bind () = section_hard "Send a zkApp transaction to update permissions" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_permissions) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_update_permissions ) in let%bind () = section_hard @@ -694,7 +700,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let nonce = Account.Nonce.of_int 1 in section_hard "Send an invalid payment from zkApp account" (send_payment_from_zkapp_account ~constraint_constants ~logger sender - nonce ~node_uri:(Network.Node.get_ingress_uri node) + nonce + ~node_uri:(Network.Node.get_ingress_uri node) ~expected_failure: Network_pool.Transaction_pool.Diff_versioned.Diff_error.( to_string_name Fee_payer_not_permitted_to_send) ) @@ -705,7 +712,9 @@ 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 = - get_account_permissions ~logger (Network.Node.get_ingress_uri node) account_id + get_account_permissions ~logger + (Network.Node.get_ingress_uri node) + account_id in if Permissions.equal ledger_permissions permissions_updated then ( [%log info] "Ledger, updated permissions are equal" ; @@ -725,44 +734,53 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkapp with an insufficient fee" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_fee - "Insufficient fee" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_insufficient_fee "Insufficient fee" ) in (* Won't be accepted until the previous transactions are applied *) let%bind () = section_hard "Send a zkApp transaction to update all fields" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_all) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_update_all ) in let%bind () = section_hard "Send a zkapp with an invalid proof" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_proof - "Verification_failed" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_invalid_proof "Verification_failed" ) in let%bind () = section_hard "Send a zkapp with an insufficient replace fee" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_replace_fee - "Insufficient_replace_fee" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid nonce" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_nonce - "Invalid_nonce" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_invalid_nonce "Invalid_nonce" ) in let%bind () = section_hard "Send a zkApp transaction with insufficient_funds, fee too high" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_insufficient_funds - "Insufficient_funds" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_insufficient_funds "Insufficient_funds" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid signature" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_invalid_signature - "Verification_failed" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_invalid_signature "Verification_failed" ) in let%bind () = section_hard "Send a zkApp transaction with a nonexistent fee payer" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_nonexistent_fee_payer - "Fee_payer_account_not_found" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_nonexistent_fee_payer "Fee_payer_account_not_found" ) in let%bind () = section_hard @@ -772,19 +790,27 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section_hard "Send a zkApp transaction to mint token" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_mint_token) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_mint_token ) in let%bind () = section_hard "Send a zkApp transaction to mint 2nd token" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_mint_token2) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_mint_token2 ) in let%bind () = section_hard "Send a zkApp transaction to transfer tokens" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_token_transfer) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_token_transfer ) in let%bind () = section_hard "Send a zkApp transaction to transfer tokens (2)" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_token_transfer2) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_token_transfer2 ) in let%bind () = section_hard "Wait for zkApp transaction to mint token" @@ -808,7 +834,9 @@ 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 = - get_account_update ~logger (Network.Node.get_ingress_uri node) account_id + get_account_update ~logger + (Network.Node.get_ingress_uri node) + account_id in if compatible_updates ~ledger_update diff --git a/src/app/test_executive/zkapps_nonce_test.ml b/src/app/test_executive/zkapps_nonce_test.ml index b6ea3dc1c33..dad202c8f29 100644 --- a/src/app/test_executive/zkapps_nonce_test.ml +++ b/src/app/test_executive/zkapps_nonce_test.ml @@ -83,8 +83,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind sender_pub_key = pub_key_of_node sender in let%bind receiver_pub_key = pub_key_of_node receiver in repeat_seq ~n ~f:(fun () -> - Graphql_requests.must_send_online_payment ~logger (Network.Node.get_ingress_uri sender) ~sender_pub_key - ~receiver_pub_key ~amount:Currency.Amount.one ~fee + Graphql_requests.must_send_online_payment ~logger + (Network.Node.get_ingress_uri sender) + ~sender_pub_key ~receiver_pub_key ~amount:Currency.Amount.one ~fee >>| ignore ) let run network t = @@ -279,7 +280,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Send a zkapp commands with fee payer nonce increments and nonce \ preconditions" - (send_zkapp_batch ~logger (Network.Node.get_ingress_uri node) + (send_zkapp_batch ~logger + (Network.Node.get_ingress_uri node) [ invalid_nonce_zkapp_cmd_from_fish1; valid_zkapp_cmd_from_fish1 ] ) in let%bind () = @@ -298,7 +300,8 @@ 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 " - (send_zkapp_batch ~logger (Network.Node.get_ingress_uri node) + (send_zkapp_batch ~logger + (Network.Node.get_ingress_uri node) [ set_permission_zkapp_cmd_from_fish1 ; valid_fee_invalid_permission_zkapp_cmd_from_fish1 ; invalid_fee_invalid_permission_zkapp_cmd_from_fish1 @@ -321,7 +324,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct "Verify account update after the updated permission failed by checking \ account nonce" (let%bind { nonce = fish1_nonce; _ } = - Graphql_requests.get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:fish1_account_id |> Deferred.bind ~f:Malleable_error.or_hard_error in @@ -339,7 +343,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section_hard "Verify invalid zkapp commands are removed from transaction pool" (let%bind pooled_zkapp_commands = - Graphql_requests.get_pooled_zkapp_commands ~logger (Network.Node.get_ingress_uri node) ~pk:fish1_pk + Graphql_requests.get_pooled_zkapp_commands ~logger + (Network.Node.get_ingress_uri node) + ~pk:fish1_pk |> Deferred.bind ~f:Malleable_error.or_hard_error in [%log debug] "Pooled zkapp_commands $commands" diff --git a/src/app/test_executive/zkapps_timing.ml b/src/app/test_executive/zkapps_timing.ml index 2243b107bfe..bd65683c726 100644 --- a/src/app/test_executive/zkapps_timing.ml +++ b/src/app/test_executive/zkapps_timing.ml @@ -372,7 +372,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp to create a zkApp account with timing" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_account_with_timing) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_create_account_with_timing ) in let%bind () = section @@ -383,7 +385,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 2nd zkApp account with timing" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_second_account_with_timing) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_create_second_account_with_timing ) in let%bind () = section @@ -394,7 +398,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send zkApp to create a 3rd zkApp account with timing" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_create_third_account_with_timing) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_create_third_account_with_timing ) in let%bind () = section @@ -406,7 +412,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify zkApp timing in ledger" (let%bind ledger_update = - get_account_update ~logger (Network.Node.get_ingress_uri node) timing_account_id + get_account_update ~logger + (Network.Node.get_ingress_uri node) + timing_account_id in if compatible_updates ~ledger_update ~requested_update:timing_update then ( @@ -430,20 +438,24 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct incompatible" ) ) ) in let%bind { total_balance = before_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let%bind () = section "Send invalid zkApp with zero vesting period in timing" - (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_with_zero_vesting_period - "Zero vesting period" ) + (send_invalid_zkapp ~logger + (Network.Node.get_ingress_uri 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" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_transfer_from_timed_account) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_transfer_from_timed_account ) in let%bind () = section "Waiting for zkApp with transfer from timed account that succeeds" @@ -454,7 +466,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct get_account_balance ~logger node timing_account_id in *) let%bind { total_balance = after_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let%bind () = @@ -506,7 +519,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct use all the liquid after 1 slot. *) let%bind { liquid_balance_opt = before_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:third_timed_account_id in let before_balance_int = @@ -564,7 +578,9 @@ 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" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_transfer_from_third_timed_account) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_transfer_from_third_timed_account ) in let%bind () = section @@ -608,7 +624,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct failwith "Amount to debit more than timed account balance" in let%bind { locked_balance_opt = locked_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in (* let%bind locked_balance = @@ -618,7 +635,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct assert ( Currency.Amount.( < ) proposed_balance (Option.value_exn locked_balance |> Currency.Balance.to_amount) ) ; - send_zkapp ~logger (Network.Node.get_ingress_uri node) + send_zkapp ~logger + (Network.Node.get_ingress_uri node) zkapp_command_invalid_transfer_from_timed_account ) in let%bind () = @@ -637,7 +655,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct get_account_balance ~logger node timing_account_id in *) (let%bind { total_balance = after_invalid_balance; _ } = - Graphql_requests.must_get_account_data ~logger (Network.Node.get_ingress_uri node) + Graphql_requests.must_get_account_data ~logger + (Network.Node.get_ingress_uri node) ~account_id:timing_account_id in let after_invalid_balance_as_amount = @@ -668,7 +687,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct in let%bind () = section "Send a zkApp with invalid timing update" - (send_zkapp ~logger (Network.Node.get_ingress_uri node) zkapp_command_update_timing) + (send_zkapp ~logger + (Network.Node.get_ingress_uri node) + zkapp_command_update_timing ) in let%bind () = section "Wait for snapp with invalid timing update" @@ -677,7 +698,9 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct let%bind () = section "Verify timing has not changed" (let%bind ledger_update = - get_account_update ~logger (Network.Node.get_ingress_uri node) timing_account_id + get_account_update ~logger + (Network.Node.get_ingress_uri node) + timing_account_id in if compatible_item ledger_update.timing timing_update.timing diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index bfb2f5066f3..4eaa9965b9e 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -3,7 +3,6 @@ open Async open Mina_base open Mina_transaction - (* exclude from bisect_ppx to avoid type error on GraphQL modules *) [@@@coverage exclude_file] @@ -395,199 +394,192 @@ let must_get_account_data ~logger node_uri ~account_id = get_account_data ~logger node_uri ~account_id |> Deferred.bind ~f:Malleable_error.or_hard_error +let permissions_of_account_permissions account_permissions : + Mina_base.Permissions.t = + (* the polymorphic variants come from Partial_accounts.auth_required in Mina_graphql *) + let to_auth_required = function + | `Either -> + Mina_base.Permissions.Auth_required.Either + | `Impossible -> + Impossible + | `None -> + None + | `Proof -> + Proof + | `Signature -> + Signature + in + let open Graphql.Account in + { edit_action_state = to_auth_required account_permissions.editActionState + ; edit_state = to_auth_required account_permissions.editState + ; increment_nonce = to_auth_required account_permissions.incrementNonce + ; receive = to_auth_required account_permissions.receive + ; send = to_auth_required account_permissions.send + ; access = to_auth_required account_permissions.access + ; set_delegate = to_auth_required account_permissions.setDelegate + ; set_permissions = to_auth_required account_permissions.setPermissions + ; set_zkapp_uri = to_auth_required account_permissions.setZkappUri + ; set_token_symbol = to_auth_required account_permissions.setTokenSymbol + ; set_verification_key = + to_auth_required account_permissions.setVerificationKey + ; set_voting_for = to_auth_required account_permissions.setVotingFor + ; set_timing = to_auth_required account_permissions.setTiming + } - let permissions_of_account_permissions account_permissions : - Mina_base.Permissions.t = - (* the polymorphic variants come from Partial_accounts.auth_required in Mina_graphql *) - let to_auth_required = function - | `Either -> - Mina_base.Permissions.Auth_required.Either - | `Impossible -> - Impossible - | `None -> - None - | `Proof -> - Proof - | `Signature -> - Signature - in - let open Graphql.Account in - { edit_action_state = to_auth_required account_permissions.editActionState - ; edit_state = to_auth_required account_permissions.editState - ; increment_nonce = to_auth_required account_permissions.incrementNonce - ; receive = to_auth_required account_permissions.receive - ; send = to_auth_required account_permissions.send - ; access = to_auth_required account_permissions.access - ; set_delegate = to_auth_required account_permissions.setDelegate - ; set_permissions = to_auth_required account_permissions.setPermissions - ; set_zkapp_uri = to_auth_required account_permissions.setZkappUri - ; set_token_symbol = to_auth_required account_permissions.setTokenSymbol - ; set_verification_key = - to_auth_required account_permissions.setVerificationKey - ; set_voting_for = to_auth_required account_permissions.setVotingFor - ; set_timing = to_auth_required account_permissions.setTiming - } - - - let get_account_permissions ~logger t ~account_id = - let open Deferred.Or_error in - let open Let_syntax in - let%bind account_obj = get_account ~logger t ~account_id in - match account_obj.account with - | Some account -> ( - match account.permissions with - | Some ledger_permissions -> - return @@ permissions_of_account_permissions ledger_permissions - | None -> - fail - (Error.of_string "Could not get permissions from ledger account") - ) - | None -> - fail (Error.of_string "Could not get account from ledger") - - (* return a Account_update.Update.t with all fields `Set` to the - value in the account, or `Keep` if value unavailable, - as if this update had been applied to the account - *) - let get_account_update ~logger t ~account_id = - let open Deferred.Or_error in - let open Let_syntax in - let%bind account_obj = get_account ~logger t ~account_id in - match account_obj.account with - | Some account -> - let open Mina_base.Zkapp_basic.Set_or_keep in - let%bind app_state = - match account.zkappState with - | Some strs -> - let fields = - Array.to_list strs |> Base.List.map ~f:(fun s -> Set s) - in - return (Mina_base.Zkapp_state.V.of_list_exn fields) - | None -> - fail - (Error.of_string - (sprintf - "Expected zkApp account with an app state for public key \ - %s" - (Signature_lib.Public_key.Compressed.to_base58_check - (Mina_base.Account_id.public_key account_id) ) ) ) - in - let%bind delegate = - match account.delegate with - | Some s -> - return (Set s) - | None -> - fail (Error.of_string "Expected delegate in account") - in - let%bind verification_key = - match account.verificationKey with - | Some vk_obj -> - let data = vk_obj.verificationKey in - let hash = vk_obj.hash in - return (Set ({ data; hash } : _ With_hash.t)) - | None -> - fail - (Error.of_string - (sprintf - "Expected zkApp account with a verification key for \ - public_key %s" - (Signature_lib.Public_key.Compressed.to_base58_check - (Mina_base.Account_id.public_key account_id) ) ) ) - in - let%bind permissions = - match account.permissions with - | Some perms -> - return @@ Set (permissions_of_account_permissions perms) - | None -> - fail (Error.of_string "Expected permissions in account") - in - let%bind zkapp_uri = - match account.zkappUri with - | Some s -> - return @@ Set s - | None -> - fail (Error.of_string "Expected zkApp URI in account") - in - let%bind token_symbol = - match account.tokenSymbol with - | Some s -> - return @@ Set s - | None -> - fail (Error.of_string "Expected token symbol in account") - in - let%bind timing = - let timing = account.timing in - let cliff_amount = timing.cliffAmount in - let cliff_time = timing.cliffTime in - let vesting_period = timing.vestingPeriod in - let vesting_increment = timing.vestingIncrement in - let initial_minimum_balance = timing.initialMinimumBalance in - match - ( cliff_amount - , cliff_time - , vesting_period - , vesting_increment - , initial_minimum_balance ) - with - | None, None, None, None, None -> - return @@ Keep - | Some amt, Some tm, Some period, Some incr, Some bal -> - let cliff_amount = amt in - let%bind cliff_time = - match tm with - | `String s -> - return @@ Mina_numbers.Global_slot_since_genesis.of_string s - | _ -> - fail - (Error.of_string - "Expected string for cliff time in account timing" ) - in - let%bind vesting_period = - match period with - | `String s -> - return @@ Mina_numbers.Global_slot_span.of_string s - | _ -> - fail - (Error.of_string - "Expected string for vesting period in account timing" ) - in - let vesting_increment = incr in - let initial_minimum_balance = bal in - return - (Set - ( { initial_minimum_balance - ; cliff_amount - ; cliff_time - ; vesting_period - ; vesting_increment - } - : Mina_base.Account_update.Update.Timing_info.t ) ) - | _ -> - fail (Error.of_string "Some pieces of account timing are missing") - in - let%bind voting_for = - match account.votingFor with - | Some s -> - return @@ Set s - | None -> - fail (Error.of_string "Expected voting-for state hash in account") - in - return - ( { app_state - ; delegate - ; verification_key - ; permissions - ; zkapp_uri - ; token_symbol - ; timing - ; voting_for - } - : Mina_base.Account_update.Update.t ) +let get_account_permissions ~logger t ~account_id = + let open Deferred.Or_error in + let open Let_syntax in + let%bind account_obj = get_account ~logger t ~account_id in + match account_obj.account with + | Some account -> ( + match account.permissions with + | Some ledger_permissions -> + return @@ permissions_of_account_permissions ledger_permissions | None -> - fail (Error.of_string "Could not get account from ledger") - - - + fail (Error.of_string "Could not get permissions from ledger account") + ) + | None -> + fail (Error.of_string "Could not get account from ledger") + +(* return a Account_update.Update.t with all fields `Set` to the + value in the account, or `Keep` if value unavailable, + as if this update had been applied to the account +*) +let get_account_update ~logger t ~account_id = + let open Deferred.Or_error in + let open Let_syntax in + let%bind account_obj = get_account ~logger t ~account_id in + match account_obj.account with + | Some account -> + let open Mina_base.Zkapp_basic.Set_or_keep in + let%bind app_state = + match account.zkappState with + | Some strs -> + let fields = + Array.to_list strs |> Base.List.map ~f:(fun s -> Set s) + in + return (Mina_base.Zkapp_state.V.of_list_exn fields) + | None -> + fail + (Error.of_string + (sprintf + "Expected zkApp account with an app state for public key %s" + (Signature_lib.Public_key.Compressed.to_base58_check + (Mina_base.Account_id.public_key account_id) ) ) ) + in + let%bind delegate = + match account.delegate with + | Some s -> + return (Set s) + | None -> + fail (Error.of_string "Expected delegate in account") + in + let%bind verification_key = + match account.verificationKey with + | Some vk_obj -> + let data = vk_obj.verificationKey in + let hash = vk_obj.hash in + return (Set ({ data; hash } : _ With_hash.t)) + | None -> + fail + (Error.of_string + (sprintf + "Expected zkApp account with a verification key for \ + public_key %s" + (Signature_lib.Public_key.Compressed.to_base58_check + (Mina_base.Account_id.public_key account_id) ) ) ) + in + let%bind permissions = + match account.permissions with + | Some perms -> + return @@ Set (permissions_of_account_permissions perms) + | None -> + fail (Error.of_string "Expected permissions in account") + in + let%bind zkapp_uri = + match account.zkappUri with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected zkApp URI in account") + in + let%bind token_symbol = + match account.tokenSymbol with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected token symbol in account") + in + let%bind timing = + let timing = account.timing in + let cliff_amount = timing.cliffAmount in + let cliff_time = timing.cliffTime in + let vesting_period = timing.vestingPeriod in + let vesting_increment = timing.vestingIncrement in + let initial_minimum_balance = timing.initialMinimumBalance in + match + ( cliff_amount + , cliff_time + , vesting_period + , vesting_increment + , initial_minimum_balance ) + with + | None, None, None, None, None -> + return @@ Keep + | Some amt, Some tm, Some period, Some incr, Some bal -> + let cliff_amount = amt in + let%bind cliff_time = + match tm with + | `String s -> + return @@ Mina_numbers.Global_slot_since_genesis.of_string s + | _ -> + fail + (Error.of_string + "Expected string for cliff time in account timing" ) + in + let%bind vesting_period = + match period with + | `String s -> + return @@ Mina_numbers.Global_slot_span.of_string s + | _ -> + fail + (Error.of_string + "Expected string for vesting period in account timing" ) + in + let vesting_increment = incr in + let initial_minimum_balance = bal in + return + (Set + ( { initial_minimum_balance + ; cliff_amount + ; cliff_time + ; vesting_period + ; vesting_increment + } + : Mina_base.Account_update.Update.Timing_info.t ) ) + | _ -> + fail (Error.of_string "Some pieces of account timing are missing") + in + let%bind voting_for = + match account.votingFor with + | Some s -> + return @@ Set s + | None -> + fail (Error.of_string "Expected voting-for state hash in account") + in + return + ( { app_state + ; delegate + ; verification_key + ; permissions + ; zkapp_uri + ; token_symbol + ; timing + ; voting_for + } + : Mina_base.Account_update.Update.t ) + | None -> + fail (Error.of_string "Could not get account from ledger") type signed_command_result = { id : string @@ -718,8 +710,8 @@ let get_pooled_zkapp_commands ~logger node_uri make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) ()) in - exec_graphql_request ~logger ~node_uri ~query_name:"get_pooled_zkapp_commands" - get_pooled_zkapp_commands + exec_graphql_request ~logger ~node_uri + ~query_name:"get_pooled_zkapp_commands" get_pooled_zkapp_commands in let%bind zkapp_pool_obj = get_pooled_zkapp_commands_graphql () in let transaction_ids = From 31b67c2263d0acd6b2d8a049856df4ad6564cc1f Mon Sep 17 00:00:00 2001 From: QuiteStochastic Date: Wed, 28 Jun 2023 17:34:15 +0200 Subject: [PATCH 15/15] address nits --- .../integration_test_lib/graphql_requests.ml | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index 4eaa9965b9e..3b1e4a1d2d1 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -236,7 +236,7 @@ module Graphql = struct |}] end -(* this function will repeatedly attempt to connect to graphql port times before giving up *) +(** this function will repeatedly attempt to connect to graphql port times before giving up *) let exec_graphql_request ?(num_tries = 10) ?(retry_delay_sec = 30.0) ?(initial_delay_sec = 0.) ~logger ~node_uri ~query_name query_obj = let open Deferred.Let_syntax in @@ -441,7 +441,7 @@ let get_account_permissions ~logger t ~account_id = | None -> fail (Error.of_string "Could not get account from ledger") -(* return a Account_update.Update.t with all fields `Set` to the +(** return a Account_update.Update.t with all fields `Set` to the value in the account, or `Keep` if value unavailable, as if this update had been applied to the account *) @@ -804,13 +804,20 @@ let send_payment_with_raw_sig ~logger node_uri ~sender_pub_key ~receiver_pub_key in let variables = makeVariables ~input ~rawSignature:raw_signature () in let send_payment_obj = make variables in - let variables_json_basic = variablesToJson (serializeVariables variables) in - (* An awkward conversion from Yojson.Basic to Yojson.Safe *) - let variables_json = - Yojson.Basic.to_string variables_json_basic |> Yojson.Safe.from_string - in - [%log info] "send_payment_obj with $variables " - ~metadata:[ ("variables", variables_json) ] ; + [%log info] + "send_payment_obj with $from $to $amount $fee $memo $nonce $valid_until \ + $raw_signature " + ~metadata: + [ ("from", Signature_lib.Public_key.Compressed.to_yojson sender_pub_key) + ; ("to", Signature_lib.Public_key.Compressed.to_yojson receiver_pub_key) + ; ("amount", Currency.Amount.to_yojson amount) + ; ("fee", Currency.Fee.to_yojson fee) + ; ("memo", `String memo) + ; ("nonce", Account.Nonce.to_yojson nonce) + ; ( "valid_until" + , Mina_numbers.Global_slot_since_genesis.to_yojson valid_until ) + ; ("raw_signature", `String raw_signature) + ] ; exec_graphql_request ~logger ~node_uri ~query_name:"Send_payment_with_raw_sig_graphql" send_payment_obj in