Use more descriptive error message with no matching router (#1096)

* Use more descriptive error message with no matching router

* Extract constant
pull/1120/head
Nam Chu Hoai 2 years ago committed by GitHub
parent d66454563f
commit 245b51dba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      solidity/app/contracts/Router.sol
  2. 10
      solidity/app/test/router.test.ts

@ -9,6 +9,9 @@ import {IMessageRecipient} from "@hyperlane-xyz/core/interfaces/IMessageRecipien
import {IOutbox} from "@hyperlane-xyz/core/interfaces/IOutbox.sol"; import {IOutbox} from "@hyperlane-xyz/core/interfaces/IOutbox.sol";
abstract contract Router is AbacusConnectionClient, IMessageRecipient { 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 ============ // ============ Mutable Storage ============
mapping(uint32 => bytes32) public routers; mapping(uint32 => bytes32) public routers;
@ -30,7 +33,10 @@ abstract contract Router is AbacusConnectionClient, IMessageRecipient {
* @param _router The address the message is coming from * @param _router The address the message is coming from
*/ */
modifier onlyRemoteRouter(uint32 _origin, bytes32 _router) { 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) returns (bytes32 _router)
{ {
_router = routers[_domain]; _router = routers[_domain];
require(_router != bytes32(0), "!router"); require(_router != bytes32(0), NO_ROUTER_ENROLLED_REVERT_MESSAGE);
} }
/** /**

@ -120,7 +120,9 @@ describe('Router', async () => {
const sender = utils.addressToBytes32(nonOwner.address); const sender = utils.addressToBytes32(nonOwner.address);
await expect( await expect(
inbox.testHandle(origin, sender, recipient, message), 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 () => { it('owner can enroll remote router', async () => {
@ -128,7 +130,7 @@ describe('Router', async () => {
const remoteBytes = utils.addressToBytes32(nonOwner.address); const remoteBytes = utils.addressToBytes32(nonOwner.address);
expect(await router.isRemoteRouter(origin, remoteBytes)).to.equal(false); expect(await router.isRemoteRouter(origin, remoteBytes)).to.equal(false);
await expect(router.mustHaveRemoteRouter(origin)).to.be.revertedWith( 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)); await router.enrollRemoteRouter(origin, utils.addressToBytes32(remote));
expect(await router.isRemoteRouter(origin, remoteBytes)).to.equal(true); 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 () => { it('reverts when dispatching a message to an unenrolled remote router', async () => {
await expect( await expect(
dispatchFunction(destinationWithoutRouter), dispatchFunction(destinationWithoutRouter),
).to.be.revertedWith('!router'); ).to.be.revertedWith(
`No router enrolled for domain. Did you specify the right domain ID?`,
);
}); });
}; };

Loading…
Cancel
Save