diff --git a/packages/tendermint-rpc/src/rpcclients/httpclient.spec.ts b/packages/tendermint-rpc/src/rpcclients/httpclient.spec.ts index 5d7637cd..add473e9 100644 --- a/packages/tendermint-rpc/src/rpcclients/httpclient.spec.ts +++ b/packages/tendermint-rpc/src/rpcclients/httpclient.spec.ts @@ -1,6 +1,6 @@ import { createJsonRpcRequest } from "../jsonrpc"; import { defaultInstance } from "../testutil.spec"; -import { HttpClient } from "./httpclient"; +import { http, HttpClient } from "./httpclient"; function pendingWithoutTendermint(): void { if (!process.env.TENDERMINT_ENABLED) { @@ -8,9 +8,23 @@ function pendingWithoutTendermint(): void { } } -describe("HttpClient", () => { - const tendermintUrl = defaultInstance.url; +const tendermintUrl = defaultInstance.url; +describe("http", () => { + it("can send a health request", async () => { + pendingWithoutTendermint(); + const response = await http("POST", `http://${tendermintUrl}`, createJsonRpcRequest("health")); + expect(response).toEqual(jasmine.objectContaining({ jsonrpc: "2.0" })); + }); + + it("errors for non-open port", async () => { + await expectAsync( + http("POST", `http://localhost:56745`, createJsonRpcRequest("health")), + ).toBeRejectedWithError(/(ECONNREFUSED|Failed to fetch)/i); + }); +}); + +describe("HttpClient", () => { it("can make a simple call", async () => { pendingWithoutTendermint(); const client = new HttpClient(tendermintUrl); diff --git a/packages/tendermint-rpc/src/rpcclients/httpclient.ts b/packages/tendermint-rpc/src/rpcclients/httpclient.ts index 42950660..52beb72a 100644 --- a/packages/tendermint-rpc/src/rpcclients/httpclient.ts +++ b/packages/tendermint-rpc/src/rpcclients/httpclient.ts @@ -24,7 +24,8 @@ function filterBadStatus(res: any): any { * * For some reason, fetch does not complain about missing server-side CORS support. */ -async function http(method: "POST", url: string, request?: any): Promise { +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export async function http(method: "POST", url: string, request?: any): Promise { if (typeof fetch !== "undefined") { const body = request ? JSON.stringify(request) : undefined; return fetch(url, { method: method, body: body })