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

Return error info on tx errors #40

Merged
merged 5 commits into from
Sep 4, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/xogmios/tx_submission/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion test/support/tx_submission/test_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
28 changes: 25 additions & 3 deletions test/tx_submission_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Loading