Skip to content

Commit

Permalink
Merge pull request #594 from connext/router-cc
Browse files Browse the repository at this point in the history
[router] Add code coverage / unit tests as needed
  • Loading branch information
LayneHaber authored Dec 7, 2021
2 parents d34c6f9 + 0983143 commit 7b479c2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let newAuctionStub: SinonStub;

const auctionPayload: AuctionPayload = {
user: mkAddress("0xa"),
initiator: mkAddress("0xa"),
sendingChainId: 1337,
sendingAssetId: mkAddress("0xc"),
amount: "10000",
Expand All @@ -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,
Expand Down
57 changes: 57 additions & 0 deletions packages/router/test/bindings/messaging/statusRequest.spec.ts
Original file line number Diff line number Diff line change
@@ -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<number, string[]> = 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);
});
});
1 change: 0 additions & 1 deletion packages/router/test/lib/operations/status.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
2 changes: 1 addition & 1 deletion packages/txservice/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b479c2

Please sign in to comment.