-
Notifications
You must be signed in to change notification settings - Fork 345
Add missing fields to rpc Server.getLatestLedger response #1389
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
Changes from 2 commits
522565b
8710e78
72519de
3eb26d3
67de0fd
56efee3
2a95724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,22 @@ export namespace Api { | |||||||||||||
| id: string; | ||||||||||||||
| sequence: number; | ||||||||||||||
| protocolVersion: string; | ||||||||||||||
| closeTime: string; | ||||||||||||||
| /** a base-64 encoded {@link xdr.LedgerHeaderHistoryEntry} instance */ | ||||||||||||||
| headerXdr: xdr.LedgerHeader; | ||||||||||||||
| /** a base-64 encoded {@link xdr.LedgerCloseMeta} instance */ | ||||||||||||||
|
||||||||||||||
| /** a base-64 encoded {@link xdr.LedgerHeaderHistoryEntry} instance */ | |
| headerXdr: xdr.LedgerHeader; | |
| /** a base-64 encoded {@link xdr.LedgerCloseMeta} instance */ | |
| /** a parsed {@link xdr.LedgerHeader} instance */ | |
| headerXdr: xdr.LedgerHeader; | |
| /** a parsed {@link xdr.LedgerCloseMeta} instance */ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -295,3 +295,21 @@ export function parseRawLedger(raw: Api.RawLedgerResponse): Api.LedgerResponse { | |||||||||||||||||||||||||
| headerXdr, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export function parseRawLatestLedger( | ||||||||||||||||||||||||||
| raw: Api.RawGetLatestLedgerResponse, | ||||||||||||||||||||||||||
| ): Api.GetLatestLedgerResponse { | ||||||||||||||||||||||||||
| if (!raw.headerXdr || !raw.metadataXdr) { | ||||||||||||||||||||||||||
| throw new TypeError(`invalid response missing fields`); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| throw new TypeError(`invalid response missing fields`); | |
| let missingFields: string; | |
| if (!raw.metadataXdr && !raw.headerXdr) { | |
| missingFields = "metadataXdr and headerXdr"; | |
| } else if (!raw.metadataXdr) { | |
| missingFields = "metadataXdr"; | |
| } else { | |
| missingFields = "headerXdr"; | |
| } | |
| throw new TypeError( | |
| `invalid getLatestLedger response missing fields: ${missingFields}`, | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion returns a better error for the user
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,7 +29,25 @@ function expectLedgerEntryFound( | |||||
| }, | ||||||
| }, | ||||||
| }; | ||||||
| mockPost.mockResolvedValue(mockResponse); | ||||||
| mockPost.mockImplementation((_: any, body: any) => { | ||||||
| if (body && body.method === "getLatestLedger") { | ||||||
| return Promise.resolve({ | ||||||
| data: { | ||||||
| result: { | ||||||
| id: "hashed_id", | ||||||
| sequence: 123, | ||||||
| protocolVersion: 20, | ||||||
|
||||||
| protocolVersion: 20, | |
| protocolVersion: "20", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We define protocolVersion as a string in GetLatestLedgerResponse. Is this using a different type?
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { StellarSdk } from "../../../test-utils/stellar-sdk-import"; | |||||
| import { serverUrl } from "../../../constants"; | ||||||
|
|
||||||
| const { Server } = StellarSdk.rpc; | ||||||
| const { xdr } = StellarSdk; | ||||||
|
|
||||||
| describe("Server#getLatestLedger", () => { | ||||||
| let server: any; | ||||||
|
|
@@ -23,12 +24,25 @@ describe("Server#getLatestLedger", () => { | |||||
| id: "hashed_id", | ||||||
| sequence: 123, | ||||||
| protocolVersion: 20, | ||||||
|
||||||
| protocolVersion: 20, | |
| protocolVersion: "20", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: finish adding added 😉