From a5c6a468f4a7ad29fb5277e08c6b8b208383a575 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sat, 16 Oct 2021 01:30:06 -0400 Subject: [PATCH] Better errors when non-string address or ENS name is passed into Contracts or provider methods (#1051). --- packages/contracts/src.ts/index.ts | 4 ++++ packages/providers/src.ts/base-provider.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/packages/contracts/src.ts/index.ts b/packages/contracts/src.ts/index.ts index 60fe04c52..6070ce6ba 100644 --- a/packages/contracts/src.ts/index.ts +++ b/packages/contracts/src.ts/index.ts @@ -116,6 +116,10 @@ const allowedTransactionKeys: { [ key: string ]: boolean } = { async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise): Promise { const name = await nameOrPromise; + if (typeof(name) !== "string") { + logger.throwArgumentError("invalid address or ENS name", "name", name); + } + // If it is already an address, just use it (after adding checksum) try { return getAddress(name); diff --git a/packages/providers/src.ts/base-provider.ts b/packages/providers/src.ts/base-provider.ts index cd43ca93b..7b4a69a66 100644 --- a/packages/providers/src.ts/base-provider.ts +++ b/packages/providers/src.ts/base-provider.ts @@ -1313,6 +1313,11 @@ export class BaseProvider extends Provider implements EnsProvider { } async _getAddress(addressOrName: string | Promise): Promise { + addressOrName = await addressOrName; + if (typeof(addressOrName) !== "string") { + logger.throwArgumentError("invalid address or ENS name", "name", addressOrName); + } + const address = await this.resolveName(addressOrName); if (address == null) { logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, {