From 55a28a26ed91df98dd0495b0b8303d4d03145deb Mon Sep 17 00:00:00 2001 From: Przemyslaw Rzad Date: Mon, 20 Jun 2022 13:37:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=BA=20More=20extensive=20check=20for?= =?UTF-8?q?=20provider=20object=20in=20`renderWeb3Hook`=20(#830)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/silent-fans-tap.md | 5 +++++ packages/core/src/testing/renderWeb3Hook.tsx | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/silent-fans-tap.md diff --git a/.changeset/silent-fans-tap.md b/.changeset/silent-fans-tap.md new file mode 100644 index 000000000..0eb22f8b1 --- /dev/null +++ b/.changeset/silent-fans-tap.md @@ -0,0 +1,5 @@ +--- +"@usedapp/core": patch +--- + +🐺 More extensive check for provider object in `renderWeb3Hook` diff --git a/packages/core/src/testing/renderWeb3Hook.tsx b/packages/core/src/testing/renderWeb3Hook.tsx index f87fdeb15..b735f6d49 100644 --- a/packages/core/src/testing/renderWeb3Hook.tsx +++ b/packages/core/src/testing/renderWeb3Hook.tsx @@ -5,6 +5,7 @@ import React from 'react' import { deployMulticall, getWaitUtils, IdentityWrapper, mineBlock } from './utils' import { BlockNumbersProvider } from '../providers/blockNumber/blockNumbers' import { ReadonlyNetworksProvider } from '../providers/network' +import { providers as ethersProviders } from 'ethers' export interface renderWeb3HookOptions { mockProvider?: MockProvider | Record @@ -55,9 +56,17 @@ export const renderWeb3Hook = async ( } const providerObject = options?.mockProvider || new MockProvider() - if (providerObject instanceof MockProvider) { - defaultProvider = providerObject - await addSingleProvider(providerObject) + if ( + providerObject instanceof MockProvider || + /** + * We still expect this to be a MockProvider, + * but this is an override in case a different instance of the provider package is used + * and the TS types are not matching. + */ + ethersProviders.Web3Provider.isProvider(providerObject) + ) { + defaultProvider = providerObject as MockProvider + await addSingleProvider(providerObject as MockProvider) } else { for (const chainIdString in providerObject) { const chainId = Number(chainIdString)