From 545a64d00fe01554045c68fa07f2c8a7a77a3138 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 4 Sep 2024 06:56:28 -0400 Subject: [PATCH 1/5] Return error info on tx_submission error. --- lib/xogmios/tx_submission/server.ex | 4 ++-- test/tx_submission_test.exs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/xogmios/tx_submission/server.ex b/lib/xogmios/tx_submission/server.ex index e92e9eb..3e52c41 100644 --- a/lib/xogmios/tx_submission/server.ex +++ b/lib/xogmios/tx_submission/server.ex @@ -15,8 +15,8 @@ defmodule Xogmios.TxSubmission.Server do {:ok, state} end - defp handle_message(%{"error" => %{"message" => message}}, state) do - GenServer.reply(state.caller, {:error, message}) + defp handle_message(%{"error" => error_info}, state) do + GenServer.reply(state.caller, {:error, error_info}) {:ok, state} end diff --git a/test/tx_submission_test.exs b/test/tx_submission_test.exs index 787f65e..d4690e7 100644 --- a/test/tx_submission_test.exs +++ b/test/tx_submission_test.exs @@ -38,18 +38,18 @@ defmodule Xogmios.TxSubmissionTest do assert {:ok, %{"transaction" => %{"id" => _id}}} = DummyClient.submit_tx(_cbor = "valid-cbor-value") - assert {:error, reason} = + assert {:error, info} = DummyClient.submit_tx(_cbor = "invalid-cbor-value") - assert reason =~ "Invalid transaction" - end + assert info["code"] == -32602 + assert data = info["data"] + eras = Map.keys(data) - test "transaction evaluation" do - pid = start_supervised!({DummyClient, url: @ws_url}) - assert is_pid(pid) - Process.sleep(1_000) + for era <- eras do + assert era in ["allegra", "alonzo", "babbage", "conway", "mary", "shelley"] + assert data[era] =~ "invalid or incomplete value of" + end - assert {:ok, [%{"budget" => _budget, "validator" => _validator}]} = - DummyClient.evaluate_tx(_cbor = "valid-cbor-value") + assert info["message"] =~ "Invalid transaction" end end From b0893cee836b6673bfd833f4ff00ddd7cce8449a Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 4 Sep 2024 07:08:44 -0400 Subject: [PATCH 2/5] Add evaluate_tx test --- test/support/tx_submission/test_handler.ex | 36 +++++++++++++++++++++- test/tx_submission_test.exs | 25 ++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/test/support/tx_submission/test_handler.ex b/test/support/tx_submission/test_handler.ex index fa92230..b468f03 100644 --- a/test/support/tx_submission/test_handler.ex +++ b/test/support/tx_submission/test_handler.ex @@ -27,7 +27,12 @@ defmodule TxSubmission.TestHandler do @valid_tx_evaluation_cbor %{ "method" => "evaluateTransaction", - "params" => %{"transaction" => %{"cbor" => "valid-cbor-value"}} + "params" => %{"transaction" => %{"cbor" => "valid-cbor-value-evaluate"}} + } + + @invalid_tx_evaluation_cbor %{ + "method" => "evaluateTransaction", + "params" => %{"transaction" => %{"cbor" => "invalid-cbor-value-evaluate"}} } @impl true @@ -91,6 +96,35 @@ defmodule TxSubmission.TestHandler do {:reply, {:text, payload}, state} + {:ok, @invalid_tx_evaluation_cbor} -> + payload = + Jason.encode!(%{ + "error" => %{ + "code" => -32_602, + "data" => %{ + "allegra" => + "invalid or incomplete value of type 'Transaction': Size mismatch when decoding Object / Array. Expected 3, but found 4.", + "alonzo" => + "invalid or incomplete value of type 'Transaction': expected list len or indef", + "babbage" => + "invalid or incomplete value of type 'Transaction': Failed to decode AuxiliaryData", + "conway" => + "invalid or incomplete value of type 'Transaction': Failed to decode AuxiliaryData", + "mary" => + "invalid or incomplete value of type 'Transaction': Size mismatch when decoding Object / Array. Expected 3, but found 4.", + "shelley" => + "invalid or incomplete value of type 'Transaction': Size mismatch when decoding Object / Array. Expected 3, but found 4." + }, + "message" => + "Invalid transaction; It looks like the given transaction wasn't well-formed. Note that I try to decode the transaction in every possible era and it was malformed in ALL eras. Yet, I can't pinpoint the exact issue for I do not know in which era / format you intended the transaction to be. The 'data' field, therefore, contains errors for each era." + }, + "id" => nil, + "jsonrpc" => "2.0", + "method" => "evaluateTransaction" + }) + + {:reply, {:text, payload}, state} + result -> Logger.error("Did not match #{inspect(result)}") {:reply, {:text, payload}, state} diff --git a/test/tx_submission_test.exs b/test/tx_submission_test.exs index d4690e7..99009bf 100644 --- a/test/tx_submission_test.exs +++ b/test/tx_submission_test.exs @@ -41,7 +41,30 @@ defmodule Xogmios.TxSubmissionTest do assert {:error, info} = DummyClient.submit_tx(_cbor = "invalid-cbor-value") - assert info["code"] == -32602 + assert info["code"] == -32_602 + assert data = info["data"] + eras = Map.keys(data) + + for era <- eras do + assert era in ["allegra", "alonzo", "babbage", "conway", "mary", "shelley"] + assert data[era] =~ "invalid or incomplete value of" + end + + assert info["message"] =~ "Invalid transaction" + end + + test "transaction evaluation" do + pid = start_supervised!({DummyClient, url: @ws_url}) + assert is_pid(pid) + Process.sleep(1_000) + + assert {:ok, [%{"budget" => _budget, "validator" => _validator}]} = + DummyClient.evaluate_tx(_cbor = "valid-cbor-value-evaluate") + + assert {:error, info} = + DummyClient.evaluate_tx(_cbor = "invalid-cbor-value-evaluate") + + assert info["code"] == -32_602 assert data = info["data"] eras = Map.keys(data) From 7cd140c418dc8dd6cb661964be0d4135987d803a Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 4 Sep 2024 07:13:00 -0400 Subject: [PATCH 3/5] Refactor --- test/tx_submission_test.exs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/tx_submission_test.exs b/test/tx_submission_test.exs index 99009bf..2061ea6 100644 --- a/test/tx_submission_test.exs +++ b/test/tx_submission_test.exs @@ -2,6 +2,7 @@ defmodule Xogmios.TxSubmissionTest do use ExUnit.Case @ws_url TestServer.get_url() + @eras ["allegra", "alonzo", "babbage", "conway", "mary", "shelley"] setup_all do {:ok, _server} = TestServer.start(handler: TxSubmission.TestHandler) @@ -46,7 +47,7 @@ defmodule Xogmios.TxSubmissionTest do eras = Map.keys(data) for era <- eras do - assert era in ["allegra", "alonzo", "babbage", "conway", "mary", "shelley"] + assert era in @eras assert data[era] =~ "invalid or incomplete value of" end @@ -69,7 +70,7 @@ defmodule Xogmios.TxSubmissionTest do eras = Map.keys(data) for era <- eras do - assert era in ["allegra", "alonzo", "babbage", "conway", "mary", "shelley"] + assert era in @eras assert data[era] =~ "invalid or incomplete value of" end From 1e3dfdecaa1719ac101c237e4a9ab17093370926 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 4 Sep 2024 07:14:18 -0400 Subject: [PATCH 4/5] Cleanup --- test/tx_submission_test.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/tx_submission_test.exs b/test/tx_submission_test.exs index 2061ea6..0ddb52b 100644 --- a/test/tx_submission_test.exs +++ b/test/tx_submission_test.exs @@ -44,9 +44,8 @@ defmodule Xogmios.TxSubmissionTest do assert info["code"] == -32_602 assert data = info["data"] - eras = Map.keys(data) - for era <- eras do + for era <- Map.keys(data) do assert era in @eras assert data[era] =~ "invalid or incomplete value of" end @@ -67,9 +66,8 @@ defmodule Xogmios.TxSubmissionTest do assert info["code"] == -32_602 assert data = info["data"] - eras = Map.keys(data) - for era <- eras do + for era <- Map.keys(data) do assert era in @eras assert data[era] =~ "invalid or incomplete value of" end From 2ca298a62b21329a885ebaafe156f1ff4fcfc820 Mon Sep 17 00:00:00 2001 From: Carlos Souza Date: Wed, 4 Sep 2024 11:22:17 -0400 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5f5a59..92de8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Errors on tx submission and tx evaluation now return complete information from Ogmios. + ## [v0.5.0](https://github.com/wowica/xogmios/releases/tag/v0.5.0) (2024-08-16) ### Added