Skip to content

Commit

Permalink
Add evaluate_tx test
Browse files Browse the repository at this point in the history
  • Loading branch information
caike committed Sep 4, 2024
1 parent 545a64d commit b0893ce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
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
25 changes: 24 additions & 1 deletion test/tx_submission_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b0893ce

Please sign in to comment.