From 8cb307e494f05aa7fbe8569541c3c73c66c4c755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Uster?= Date: Fri, 3 Feb 2023 15:30:34 +0100 Subject: [PATCH 1/3] playbook: return proper value after an error --- lib/archethic/utils/regression/playbook.ex | 2 ++ mix.lock | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/archethic/utils/regression/playbook.ex b/lib/archethic/utils/regression/playbook.ex index 1512d21fb..9c52f1bb9 100644 --- a/lib/archethic/utils/regression/playbook.ex +++ b/lib/archethic/utils/regression/playbook.ex @@ -222,6 +222,8 @@ defmodule Archethic.Utils.Regression.Playbook do Logger.error( "Transaction #{Base.encode16(tx.address)} submission fails - #{inspect(reason)}" ) + + {:error, reason} end end diff --git a/mix.lock b/mix.lock index fed321920..a2b9740a4 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "absinthe": {:hex, :absinthe, "1.7.0", "36819e7b1fd5046c9c734f27fe7e564aed3bda59f0354c37cd2df88fd32dd014", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "566a5b5519afc9b29c4d367f0c6768162de3ec03e9bf9916f9dc2bcbe7c09643"}, + "absinthe": {:hex, :absinthe, "1.7.1", "aca6f64994f0914628429ddbdfbf24212747b51780dae189dd98909da911757b", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.2.2 or ~> 1.3.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c0c4dbd93881fa3bfbad255608234b104b877c2a901850c1fe8c53b408a72a57"}, "absinthe_phoenix": {:hex, :absinthe_phoenix, "2.0.2", "e607b438db900049b9b3760f8ecd0591017a46122fffed7057bf6989020992b5", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:absinthe_plug, "~> 1.5", [hex: :absinthe_plug, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.5", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.13 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}], "hexpm", "d36918925c380dc7d2ed7d039c9a3b4182ec36723f7417a68745ade5aab22f8d"}, "absinthe_plug": {:hex, :absinthe_plug, "1.5.8", "38d230641ba9dca8f72f1fed2dfc8abd53b3907d1996363da32434ab6ee5d6ab", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bbb04176647b735828861e7b2705465e53e2cf54ccf5a73ddd1ebd855f996e5a"}, "artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"}, @@ -39,7 +39,7 @@ "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.34.0", "002d0cc194b48794d74711731db004fafeb328fe676976f160685262d43706a8", [:mix], [], "hexpm", "9c3a9f43f40dde00332a589bd9d389b90c1f518aef500364d00636acc5ebc99c"}, "flow": {:hex, :flow, "1.2.3", "1d9239be6a6ec8ef33f22200c8d8b3a756a28145476c7e096fbb3fda04e12f5c", [:mix], [{:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}], "hexpm", "77eeb976cb5152a1168290ce9015b8b2d41b70eb5265a36d7538a817237891d9"}, - "gen_stage": {:hex, :gen_stage, "1.1.2", "b1656cd4ba431ed02c5656fe10cb5423820847113a07218da68eae5d6a260c23", [:mix], [], "hexpm", "9e39af23140f704e2b07a3e29d8f05fd21c2aaf4088ff43cb82be4b9e3148d02"}, + "gen_stage": {:hex, :gen_stage, "1.2.0", "ee49244b57803f54bdab08a60a927e1b4e5bb5d635c52eca0f376a0673af3f8c", [:mix], [], "hexpm", "c3e40992c72e74d9c4eda16d7515bf32c9e7b634e827ab11091fff3290f7b503"}, "gen_state_machine": {:hex, :gen_state_machine, "3.0.0", "1e57f86a494e5c6b14137ebef26a7eb342b3b0070c7135f2d6768ed3f6b6cdff", [:mix], [], "hexpm", "0a59652574bebceb7309f6b749d2a41b45fdeda8dbb4da0791e355dd19f0ed15"}, "git_hooks": {:hex, :git_hooks, "0.7.3", "09489e94d88dfc767662e22aff2b6208bd7cf555a19dd0e1477cca4683ce0701", [:mix], [{:blankable, "~> 1.0.0", [hex: :blankable, repo: "hexpm", optional: false]}, {:recase, "~> 0.7.0", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "d6ddedeb4d3a8602bc3f84e087a38f6150a86d9e790628ed8bc70e6d90681659"}, "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, From 18662b2218e2ec127d073ce8edd23536dcccc891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Uster?= Date: Tue, 7 Feb 2023 16:45:45 +0100 Subject: [PATCH 2/3] Support of graphql errors in playbook --- lib/archethic/utils/regression/playbook.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/archethic/utils/regression/playbook.ex b/lib/archethic/utils/regression/playbook.ex index 9c52f1bb9..451fb86ff 100644 --- a/lib/archethic/utils/regression/playbook.ex +++ b/lib/archethic/utils/regression/playbook.ex @@ -218,6 +218,9 @@ defmodule Archethic.Utils.Regression.Playbook do {:error, :timeout} end + {:ok, %{"status" => "invalid", "errors" => errors}} -> + {:error, errors} + {:error, reason} -> Logger.error( "Transaction #{Base.encode16(tx.address)} submission fails - #{inspect(reason)}" From d42c2e1bf6eed5a7f8fd24e3736a7fcfaba9b522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Uster?= Date: Tue, 7 Feb 2023 17:32:02 +0100 Subject: [PATCH 3/3] Adding network protocol in playbook params --- lib/archethic/utils/regression/playbook.ex | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/archethic/utils/regression/playbook.ex b/lib/archethic/utils/regression/playbook.ex index 451fb86ff..c17f290bf 100644 --- a/lib/archethic/utils/regression/playbook.ex +++ b/lib/archethic/utils/regression/playbook.ex @@ -92,7 +92,8 @@ defmodule Archethic.Utils.Regression.Playbook do transaction_data = %TransactionData{}, host, port, - curve \\ Crypto.default_curve() + curve \\ Crypto.default_curve(), + proto \\ :http ) do chain_length = get_chain_size(transaction_seed, curve, host, port) @@ -123,7 +124,8 @@ defmodule Archethic.Utils.Regression.Playbook do case WebClient.with_connection( host, port, - &WebClient.json(&1, "/api/transaction", tx_to_json(tx)) + &WebClient.json(&1, "/api/transaction", tx_to_json(tx)), + proto ) do {:ok, %{"status" => "pending"}} -> {:ok, tx.address} @@ -133,7 +135,7 @@ defmodule Archethic.Utils.Regression.Playbook do end end - defp get_origin_private_key(host, port) do + defp get_origin_private_key(host, port, proto \\ :http) do body = %{ "origin_public_key" => Base.encode16(@genesis_origin_public_key) } @@ -141,7 +143,8 @@ defmodule Archethic.Utils.Regression.Playbook do case WebClient.with_connection( host, port, - &WebClient.json(&1, "/api/origin_key", body) + &WebClient.json(&1, "/api/origin_key", body), + proto ) do {:ok, %{ @@ -166,7 +169,8 @@ defmodule Archethic.Utils.Regression.Playbook do transaction_data = %TransactionData{}, host, port, - curve \\ Crypto.default_curve() + curve \\ Crypto.default_curve(), + proto \\ :http ) do chain_length = get_chain_size(transaction_seed, curve, host, port) @@ -199,7 +203,8 @@ defmodule Archethic.Utils.Regression.Playbook do case WebClient.with_connection( host, port, - &WebClient.json(&1, "/api/transaction", tx_to_json(tx)) + &WebClient.json(&1, "/api/transaction", tx_to_json(tx)), + proto ) do {:ok, %{"status" => "pending"}} -> case Task.yield(replication_attestation, 5_000) || Task.shutdown(replication_attestation) do @@ -344,7 +349,7 @@ defmodule Archethic.Utils.Regression.Playbook do } end - def get_chain_size(seed, curve, host, port) do + def get_chain_size(seed, curve, host, port, proto \\ :http) do genesis_address = seed |> Crypto.derive_keypair(0, curve) @@ -354,7 +359,7 @@ defmodule Archethic.Utils.Regression.Playbook do query = ~s|query {last_transaction(address: "#{Base.encode16(genesis_address)}"){ chainLength }}| - case WebClient.with_connection(host, port, &WebClient.query(&1, query)) do + case WebClient.with_connection(host, port, &WebClient.query(&1, query), proto) do {:ok, %{"errors" => [%{"message" => "transaction_not_exists"}]}} -> 0 @@ -362,14 +367,14 @@ defmodule Archethic.Utils.Regression.Playbook do chain_length {:error, error_info} -> - raise "chain size failed #{error_info}" + raise "chain size failed #{inspect(error_info)}" end end - def get_uco_balance(address, host, port) do + def get_uco_balance(address, host, port, proto \\ :http) do query = ~s|query {lastTransaction(address: "#{Base.encode16(address)}"){ balance { uco }}}| - case WebClient.with_connection(host, port, &WebClient.query(&1, query)) do + case WebClient.with_connection(host, port, &WebClient.query(&1, query), proto) do {:ok, %{"data" => %{"lastTransaction" => %{"balance" => %{"uco" => uco}}}}} -> uco @@ -383,16 +388,16 @@ defmodule Archethic.Utils.Regression.Playbook do "uco" => uco } } - }} = WebClient.with_connection(host, port, &WebClient.query(&1, balance_query)) + }} = WebClient.with_connection(host, port, &WebClient.query(&1, balance_query), proto) uco end end - def storage_nonce_public_key(host, port) do + def storage_nonce_public_key(host, port, proto \\ :http) do query = ~s|query {sharedSecrets { storageNoncePublicKey}}| - case WebClient.with_connection(host, port, &WebClient.query(&1, query)) do + case WebClient.with_connection(host, port, &WebClient.query(&1, query), proto) do {:ok, %{ "data" => %{