Skip to content

Commit

Permalink
Move the cursor field in rpc.Server.getEvents to the right place (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic authored Dec 17, 2024
1 parent 3988271 commit 548e5c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export namespace Api {
export interface GetEventsResponse {
latestLedger: number;
events: EventResponse[];
cursor: string;
}

export interface EventResponse extends BaseEventResponse {
Expand All @@ -203,14 +204,14 @@ export namespace Api {
export interface RawGetEventsResponse {
latestLedger: number;
events: RawEventResponse[];
cursor: string;
}

interface BaseEventResponse {
id: string;
type: EventType;
ledger: number;
ledgerClosedAt: string;
cursor: string;
pagingToken: string;
inSuccessfulContractCall: boolean;
txHash: string;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function parseRawEvents(
): Api.GetEventsResponse {
return {
latestLedger: raw.latestLedger,
cursor: raw.cursor,
events: (raw.events ?? []).map((evt) => {
const clone: Omit<Api.RawEventResponse, 'contractId'> = { ...evt };
delete (clone as any).contractId; // `as any` hack because contractId field isn't optional
Expand Down
10 changes: 9 additions & 1 deletion test/unit/server/soroban/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ describe("Server#getEvents", function () {
});

it("requests the correct endpoint", function (done) {
let result = { latestLedger: 0, events: [] };
let result = {
cursor: "164090849041387521-3",
latestLedger: 0,
events: [],
};
setupMock(
this.axiosMock,
{
Expand All @@ -38,6 +42,7 @@ describe("Server#getEvents", function () {
it("can build wildcard filters", function (done) {
let result = {
latestLedger: 1,
cursor: "164090849041387521-3",
events: filterEvents(getEventsResponseFixture, "*/*"),
};
expect(result.events).to.not.have.lengthOf(0, JSON.stringify(result));
Expand Down Expand Up @@ -76,6 +81,7 @@ describe("Server#getEvents", function () {
it("can build matching filters", function (done) {
let result = {
latestLedger: 1,
cursor: "164090849041387521-3",
events: filterEvents(
getEventsResponseFixture,
`${topicVals[0]}/${topicVals[1]}`,
Expand Down Expand Up @@ -116,6 +122,7 @@ describe("Server#getEvents", function () {
it("can build mixed filters", function (done) {
let result = {
latestLedger: 3,
cursor: "164090849041387521-3",
events: filterEventsByLedger(
filterEvents(getEventsResponseFixture, `${topicVals[0]}/*`),
2,
Expand Down Expand Up @@ -156,6 +163,7 @@ describe("Server#getEvents", function () {
it("can paginate", function (done) {
let result = {
latestLedger: 3,
cursor: "164090849041387521-3",
events: filterEventsByLedger(
filterEvents(getEventsResponseFixture, "*/*"),
2,
Expand Down

0 comments on commit 548e5c3

Please sign in to comment.