From 0983143bd5eea51b366717f307c9b4be2193737b Mon Sep 17 00:00:00 2001 From: Jake Kidd Date: Tue, 7 Dec 2021 14:14:37 -0800 Subject: [PATCH] add cc for statusRequest --- .../bindings/messaging/auctionRequest.spec.ts | 2 + .../bindings/messaging/statusRequest.spec.ts | 57 +++++++++++++++++++ .../router/test/lib/operations/status.spec.ts | 1 - packages/txservice/src/error.ts | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 packages/router/test/bindings/messaging/statusRequest.spec.ts diff --git a/packages/router/test/bindings/messaging/auctionRequest.spec.ts b/packages/router/test/bindings/messaging/auctionRequest.spec.ts index da7b2d4724..fbe5abf51c 100644 --- a/packages/router/test/bindings/messaging/auctionRequest.spec.ts +++ b/packages/router/test/bindings/messaging/auctionRequest.spec.ts @@ -17,6 +17,7 @@ let newAuctionStub: SinonStub; const auctionPayload: AuctionPayload = { user: mkAddress("0xa"), + initiator: mkAddress("0xa"), sendingChainId: 1337, sendingAssetId: mkAddress("0xc"), amount: "10000", @@ -34,6 +35,7 @@ const auctionPayload: AuctionPayload = { const bid: AuctionBid = { user: auctionPayload.user, router: mkAddress("0xccc"), + initiator: auctionPayload.user, sendingChainId: auctionPayload.sendingChainId, sendingAssetId: auctionPayload.sendingAssetId, amount: auctionPayload.amount, diff --git a/packages/router/test/bindings/messaging/statusRequest.spec.ts b/packages/router/test/bindings/messaging/statusRequest.spec.ts new file mode 100644 index 0000000000..ade4349ffb --- /dev/null +++ b/packages/router/test/bindings/messaging/statusRequest.spec.ts @@ -0,0 +1,57 @@ +import { + createLoggingContext, + expect, + jsonifyError, + mkAddress, + mkBytes32, + StatusResponse, + txDataMock, +} from "@connext/nxtp-utils"; +import { reset, restore, SinonStub, stub } from "sinon"; +import { statusRequestBinding } from "../../../src/bindings/messaging/statusRequest"; +import { messagingMock } from "../../globalTestHook"; +import * as operations from "../../../src/lib/operations"; + +let getStatusStub: SinonStub; + +const inbox = "inbox"; +const from = mkAddress("0xfff"); +const mockSwapPools: Map = new Map(); +mockSwapPools.set(txDataMock.sendingChainId, [txDataMock.sendingAssetId]); +mockSwapPools.set(txDataMock.receivingChainId, [txDataMock.receivingAssetId]); +const mockStatusResponse: StatusResponse = { + routerVersion: "v69.420", + routerAddress: mkAddress("0xabc123"), + signerAddress: mkAddress("0xdef456"), + trackerLength: 12, + swapPools: mockSwapPools, + supportedChains: [txDataMock.sendingChainId, txDataMock.receivingChainId], +}; + +const { requestContext } = createLoggingContext("statusRequestBinding", undefined, mkBytes32()); + +describe("#statusRequestBinding", () => { + beforeEach(async () => { + getStatusStub = stub().resolves(mockStatusResponse); + stub(operations, "getOperations").returns({ + getStatus: getStatusStub, + } as any); + }); + + afterEach(() => { + restore(); + reset(); + }); + + it("should work", async () => { + await statusRequestBinding(from, inbox, undefined, undefined, requestContext); + expect(getStatusStub.callCount).to.eq(1); + expect(messagingMock.publishStatusResponse).to.be.calledOnceWith(from, inbox, mockStatusResponse); + }); + + it("should return without publishing if error in status response", async () => { + await statusRequestBinding(from, inbox, undefined, jsonifyError(new Error("fail")), requestContext); + expect(getStatusStub.callCount).to.eq(0); + expect(messagingMock.publishStatusResponse.callCount).to.eq(0); + }); +}); diff --git a/packages/router/test/lib/operations/status.spec.ts b/packages/router/test/lib/operations/status.spec.ts index 78d0ea6acd..e067a1ee71 100644 --- a/packages/router/test/lib/operations/status.spec.ts +++ b/packages/router/test/lib/operations/status.spec.ts @@ -7,7 +7,6 @@ const { requestContext } = createLoggingContext("TEST", undefined, mkBytes32("0x describe("Status Operation", () => { it("should work", async () => { const res = await getStatus(requestContext); - console.log("res", res); expect(res).to.be.ok; }); }); diff --git a/packages/txservice/src/error.ts b/packages/txservice/src/error.ts index 66b7c58d15..61cc772192 100644 --- a/packages/txservice/src/error.ts +++ b/packages/txservice/src/error.ts @@ -340,7 +340,7 @@ export const parseError = (error: any): NxtpError => { } let message = error.message; - if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof error.error.message === "string") { + if (error.error && typeof error.error.message === "string") { message = error.error.message; } else if (typeof error.body === "string") { message = error.body;