Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playbook: return proper value after an error #886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions lib/archethic/utils/regression/playbook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand All @@ -133,15 +135,16 @@ 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)
}

case WebClient.with_connection(
host,
port,
&WebClient.json(&1, "/api/origin_key", body)
&WebClient.json(&1, "/api/origin_key", body),
proto
) do
{:ok,
%{
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -218,10 +223,15 @@ 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)}"
)

{:error, reason}
end
end

Expand Down Expand Up @@ -339,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)
Expand All @@ -349,22 +359,22 @@ 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

{:ok, %{"data" => %{"last_transaction" => %{"chainLength" => chain_length}}}} ->
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

Expand All @@ -378,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" => %{
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down