Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ A breaking change will get clearly marked in this log.
* Introduced an `rpc.Server.getAssetBalance()` helper to fetch asset balances both for contracts and accounts ([#1286](https://github.com/stellar/js-stellar-sdk/pull/1286/)).
* `rpc.Api.BalanceResponse` now can include a `revocable` field in its `balanceEntry` for when trustlines are fetched ([#1286](https://github.com/stellar/js-stellar-sdk/pull/1286/)).

### Fixed
* `Api.RawEventResponse.topics` is now optional to reflect topicless events ([#1292](https://github.com/stellar/js-stellar-sdk/pull/1292)).
* `parseRawEvents` correctly checks if `Api.RawEventResponse.topics` is undefined ([#1292](https://github.com/stellar/js-stellar-sdk/pull/1292)).

## [v14.3.3](https://github.com/stellar/js-stellar-sdk/compare/v14.3.2...v14.3.3)

### Added
* `Spec.nativeToScVal` supports parsing Muxed Address([#1274](https://github.com/stellar/js-stellar-sdk/pull/1274)),


## [v14.3.2](https://github.com/stellar/js-stellar-sdk/compare/v14.3.1...v14.3.2)

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export namespace Api {

export interface RawEventResponse extends BaseEventResponse {
contractId: string;
topic: string[];
topic?: string[];
value: string;
}

Expand Down
4 changes: 3 additions & 1 deletion src/rpc/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export function parseRawEvents(
...(evt.contractId !== "" && {
contractId: new Contract(evt.contractId),
}),
topic: evt.topic.map((topic) => xdr.ScVal.fromXDR(topic, "base64")),
topic: (evt.topic ?? []).map((topic) =>
xdr.ScVal.fromXDR(topic, "base64"),
),
value: xdr.ScVal.fromXDR(evt.value, "base64"),
};
}),
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export class RpcServer {

// Coalesce to a strkey
if (typeof address === "string") {
addr = address;
} else if (address instanceof Address) {
addr = address.toString();
} else if (address instanceof Contract) {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/server/soroban/get_events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function filterEvents(events: any[], filter: string): any[] {
const parts = filter.split("/");
return events.filter(
(e: any) =>
e.topic &&
e.topic.length === parts.length &&
e.topic.every((s: any, j: number) => s === parts[j] || parts[j] === "*"),
);
Expand Down Expand Up @@ -86,6 +87,20 @@ const getEventsResponseFixture = [
value: eventVal,
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c",
},
{
type: "contract",
ledger: "4",
ledgerClosedAt: "2025-10-26T22:19:10Z",
contractId: "CC5E2AZW4DRFDYZHI7M25QKCSMFPUD7C3425BUOW54RU3TQRKUPA64W5",
id: "0005426983236280320-0000000000",
cursor: "0005426983236280320-0000000000",
operationIndex: 0,
transactionIndex: 2,
inSuccessfulContractCall: true,
txHash: "8735d2c7e31b1f10037f41d723072fbfacd0bbf74ed48f71f8e4211132017123",
// topic is undefined to test the fix for the bug
value: eventVal,
},
];

describe("Server#getEvents", () => {
Expand Down Expand Up @@ -353,4 +368,23 @@ describe("Server#getEvents", () => {
});
expect(mockPost).toHaveBeenCalledTimes(1);
});

it("handles events with undefined topic field", async () => {
const result = {
latestLedger: 3,
oldestLedger: 3,
oldestLedgerCloseTime: "0",
latestLedgerCloseTime: "0",
cursor: "164090849041387521-3",
events: filterEventsByLedger(getEventsResponseFixture, 4),
};
console.log(result);
setupMock(mockPost, { startLedger: 4 }, result);

const response = await server.getEvents({ startLedger: 4 });
const parsed = parseEvents(result);
expect(response).toEqual(parsed);
expect(response.events[0].topic).toEqual([]);
expect(mockPost).toHaveBeenCalledTimes(1);
});
});
Loading