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

Move the cursor field in rpc.Server.getEvents to the right place #1124

Merged
merged 2 commits into from
Dec 17, 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
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
Loading