Skip to content

Commit

Permalink
Merge pull request #5229 from connext/handle-unsupported-error-in-rou…
Browse files Browse the repository at this point in the history
…ter-executer

fix: handle unsupported error in router executer
  • Loading branch information
wanglonghong authored Nov 28, 2023
2 parents 5ad9ebf + 8cf3057 commit 2dc9dde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/agents/router/src/tasks/executor/operations/execute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ajv, createLoggingContext, ExecuteArgs, ExecuteArgsSchema } from "@connext/nxtp-utils";

import { DomainNotSupported } from "../../../errors";
import { getContext } from "../executor";

import { sendExecuteSlowToSequencer } from "./sequencer";
Expand All @@ -22,16 +21,21 @@ export const execute = async (args: ExecuteArgs, transferId: string): Promise<vo

// Ensure we support the target domain (i.e. it's been configured).
if (!config.chains[args.params.destinationDomain]) {
throw new DomainNotSupported(args.params.destinationDomain, transferId, {
logger.debug("Unsupported destination domain", requestContext, methodContext, {
domain: args.params.destinationDomain,
transferId,
supportedDomains: Object.keys(config.chains),
});

return;
}

// Validate input schema
const validate = ajv.compile(ExecuteArgsSchema);
const valid = validate(args);
if (!valid) {
throw new Error(validate.errors?.map((err: unknown) => JSON.stringify(err, null, 2)).join(","));
logger.debug(validate.errors!.map((err: unknown) => JSON.stringify(err, null, 2)).join(","));
return;
}

const encodedData = contracts.connext.encodeFunctionData("execute", [args]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ describe("Operations:Execute", () => {
it("should not send to the relayer if not valid ", async () => {
const executeArgs = { ...mock.entity.executeArgs(), routers: ["0x"] };
const transferId = mkBytes32();
await expect(execute(executeArgs, transferId)).to.be.rejectedWith(Error);
await execute(executeArgs, transferId);
expect(sendExecuteFastToRelayerStub.callCount).to.be.eq(0);
});
it("should throw DomainNotSupported if not configured", async () => {
const executeArgs = { ...mock.entity.executeArgs(), params: { originDomain: "111", destinationDomain: "222" } };
const transferId = mkBytes32();
await expect(execute(executeArgs, transferId)).to.be.rejectedWith(DomainNotSupported);
await execute(executeArgs, transferId);
expect(sendExecuteFastToRelayerStub.callCount).to.be.eq(0);
});
it("should send the payload to the relayer successfully!", async () => {
Expand Down

0 comments on commit 2dc9dde

Please sign in to comment.