Skip to content

fix(api-server): surface RPC events on simulate response (#1162) - #1238

Open
gebibd00-jpg wants to merge 1 commit into
Maki-Zeninn:mainfrom
gebibd00-jpg:fix/surface-simulation-events
Open

fix(api-server): surface RPC events on simulate response (#1162)#1238
gebibd00-jpg wants to merge 1 commit into
Maki-Zeninn:mainfrom
gebibd00-jpg:fix/surface-simulation-events

Conversation

@gebibd00-jpg

Copy link
Copy Markdown
Contributor

Summary

SimulateTransactionResult.events was being parsed by the Soroban simulateTransaction deserializer but then dropped on the floor by the simulate handler — confirmed by the #[allow(dead_code)] attribute and a repo-wide grep showing no other reference to the field. The RPCs events array carries diagnostic/contract events (emitted events, failure reasons) that are useful context for callers trying to understand a simulation result, especially one that reports success: false.

Fix

  • FeeBreakdown gains an events: Vec<serde_json::Value> field with a doc comment explaining the contract: present but possibly empty on the heuristic fallback path.
  • simulate() propagates result.events into the FeeBreakdown on the live-RPC success path; the heuristic fallback path initializes events to an empty vec.
  • SimulationDetail in types.rs gains a matching events: Vec<serde_json::Value> field with #[serde(default)] so existing clients deserializing older responses without the field still parse cleanly.
  • handlers::simulate populates SimulationDetail.events from the breakdown.

Tests

Both tests stand up an in-process axum mock via tokio::net::TcpListener::bind("127.0.0.1:0") so they do not depend on any fixed port or a live RPC:

  • test_simulate_surfaces_rpc_events_in_simulation_detail — mock returns two events (a contract Transfer and a diagnostic message); asserts the API surfaces both in simulation.events.
  • test_simulate_events_empty_on_heuristic_fallback — uses the existing test_app() (RPC unreachable) and asserts simulation.events is present but empty.

I do not have a local Rust toolchain, so I could not run cargo test myself — please run the test suite before merging. The diff is mechanical: an events field threaded through four files plus two self-contained tests.

Closes

#1162

…#1162)

`SimulateTransactionResult.events` was being parsed by the Soroban
`simulateTransaction` deserializer but then dropped on the floor
by the simulate handler - confirmed by the `#[allow(dead_code)]`
attribute and a repo-wide grep showing no other reference to the
field. The RPC's `events` array carries diagnostic/contract events
(emitted events, failure reasons) that are useful context for
callers trying to understand a simulation result, especially one
that reports `success: false`.

Fix:

- `FeeBreakdown` gains an `events: Vec<serde_json::Value>` field
  with a doc comment explaining the contract: present but possibly
  empty on the heuristic fallback path.
- `simulate()` propagates `result.events` into the `FeeBreakdown`
  on the live-RPC success path; the heuristic fallback path
  initializes `events` to an empty vec.
- `SimulationDetail` in types.rs gains a matching
  `events: Vec<serde_json::Value>` field with `#[serde(default)]`
  so existing clients deserializing older responses without the
  field still parse cleanly.
- `handlers::simulate` populates `SimulationDetail.events` from
  the breakdown.

Tests (both stand up an in-process axum mock via
`tokio::net::TcpListener::bind("127.0.0.1:0")` so they don't
depend on any fixed port or a live RPC):

- `test_simulate_surfaces_rpc_events_in_simulation_detail` - mock
  returns two events (a contract Transfer and a diagnostic message);
  asserts the API surfaces both in `simulation.events`.
- `test_simulate_events_empty_on_heuristic_fallback` - uses the
  existing `test_app()` (RPC unreachable) and asserts
  `simulation.events` is present but empty.

I do not have a local Rust toolchain, so I could not run
`cargo test` myself - please run the test suite before merging.
The diff is mechanical: an `events` field threaded through four
files plus two self-contained tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant