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 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/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 787f65e..0ddb52b 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) @@ -38,10 +39,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" + assert info["code"] == -32_602 + assert data = info["data"] + + for era <- Map.keys(data) do + assert era in @eras + assert data[era] =~ "invalid or incomplete value of" + end + + assert info["message"] =~ "Invalid transaction" end test "transaction evaluation" do @@ -50,6 +59,19 @@ defmodule Xogmios.TxSubmissionTest do Process.sleep(1_000) assert {:ok, [%{"budget" => _budget, "validator" => _validator}]} = - DummyClient.evaluate_tx(_cbor = "valid-cbor-value") + 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"] + + for era <- Map.keys(data) do + assert era in @eras + assert data[era] =~ "invalid or incomplete value of" + end + + assert info["message"] =~ "Invalid transaction" end end