From 245b51dba67183963ee5907c65d2475d85ea9c38 Mon Sep 17 00:00:00 2001 From: Nam Chu Hoai Date: Mon, 26 Sep 2022 15:38:16 -0400 Subject: [PATCH] Use more descriptive error message with no matching router (#1096) * Use more descriptive error message with no matching router * Extract constant --- solidity/app/contracts/Router.sol | 10 ++++++++-- solidity/app/test/router.test.ts | 10 +++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/solidity/app/contracts/Router.sol b/solidity/app/contracts/Router.sol index c80939ca7..c12279c85 100644 --- a/solidity/app/contracts/Router.sol +++ b/solidity/app/contracts/Router.sol @@ -9,6 +9,9 @@ import {IMessageRecipient} from "@hyperlane-xyz/core/interfaces/IMessageRecipien import {IOutbox} from "@hyperlane-xyz/core/interfaces/IOutbox.sol"; abstract contract Router is AbacusConnectionClient, IMessageRecipient { + string constant NO_ROUTER_ENROLLED_REVERT_MESSAGE = + "No router enrolled for domain. Did you specify the right domain ID?"; + // ============ Mutable Storage ============ mapping(uint32 => bytes32) public routers; @@ -30,7 +33,10 @@ abstract contract Router is AbacusConnectionClient, IMessageRecipient { * @param _router The address the message is coming from */ modifier onlyRemoteRouter(uint32 _origin, bytes32 _router) { - require(_isRemoteRouter(_origin, _router), "!router"); + require( + _isRemoteRouter(_origin, _router), + NO_ROUTER_ENROLLED_REVERT_MESSAGE + ); _; } @@ -125,7 +131,7 @@ abstract contract Router is AbacusConnectionClient, IMessageRecipient { returns (bytes32 _router) { _router = routers[_domain]; - require(_router != bytes32(0), "!router"); + require(_router != bytes32(0), NO_ROUTER_ENROLLED_REVERT_MESSAGE); } /** diff --git a/solidity/app/test/router.test.ts b/solidity/app/test/router.test.ts index 4fe20b961..228d6a8f1 100644 --- a/solidity/app/test/router.test.ts +++ b/solidity/app/test/router.test.ts @@ -120,7 +120,9 @@ describe('Router', async () => { const sender = utils.addressToBytes32(nonOwner.address); await expect( inbox.testHandle(origin, sender, recipient, message), - ).to.be.revertedWith('!router'); + ).to.be.revertedWith( + `No router enrolled for domain. Did you specify the right domain ID?`, + ); }); it('owner can enroll remote router', async () => { @@ -128,7 +130,7 @@ describe('Router', async () => { const remoteBytes = utils.addressToBytes32(nonOwner.address); expect(await router.isRemoteRouter(origin, remoteBytes)).to.equal(false); await expect(router.mustHaveRemoteRouter(origin)).to.be.revertedWith( - '!router', + `No router enrolled for domain. Did you specify the right domain ID?`, ); await router.enrollRemoteRouter(origin, utils.addressToBytes32(remote)); expect(await router.isRemoteRouter(origin, remoteBytes)).to.equal(true); @@ -199,7 +201,9 @@ describe('Router', async () => { it('reverts when dispatching a message to an unenrolled remote router', async () => { await expect( dispatchFunction(destinationWithoutRouter), - ).to.be.revertedWith('!router'); + ).to.be.revertedWith( + `No router enrolled for domain. Did you specify the right domain ID?`, + ); }); };