Better errors when non-string address or ENS name is passed into Contracts or provider methods (#1051).

This commit is contained in:
Richard Moore 2021-10-16 01:30:06 -04:00
parent 8947fd405e
commit a5c6a468f4
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 9 additions and 0 deletions

@ -116,6 +116,10 @@ const allowedTransactionKeys: { [ key: string ]: boolean } = {
async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise<string>): Promise<string> { async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise<string>): Promise<string> {
const name = await nameOrPromise; 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) // If it is already an address, just use it (after adding checksum)
try { try {
return getAddress(name); return getAddress(name);

@ -1313,6 +1313,11 @@ export class BaseProvider extends Provider implements EnsProvider {
} }
async _getAddress(addressOrName: string | Promise<string>): Promise<string> { async _getAddress(addressOrName: string | Promise<string>): Promise<string> {
addressOrName = await addressOrName;
if (typeof(addressOrName) !== "string") {
logger.throwArgumentError("invalid address or ENS name", "name", addressOrName);
}
const address = await this.resolveName(addressOrName); const address = await this.resolveName(addressOrName);
if (address == null) { if (address == null) {
logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, { logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, {