defi-wonderland / smock

The Solidity mocking library
MIT License
321 stars 39 forks source link

Can't create fakes of abstract contracts after upgrading to hardhat-ethers v2.1.1 #151

Closed kkirka closed 1 year ago

kkirka commented 1 year ago

Describe the bug After upgrading hardhat-ethers to 2.1.1, I can't create fake contracts based on abstract contracts or interfaces.

Smock calls hardhat.ethers.getContractAt(contractName, "0x00…000"); to get an interface of a contract: https://github.com/defi-wonderland/smock/blob/91a7aadf0cfa14ba52edb98c15fa0d38562fef39/src/factories/ethers-interface.ts#L50

However, starting from @nomiclabs/hardhat-ethers v2.1.1 getContractAt throws an error if the on-chain code at the address is "0x".

Reproduction steps @nomiclabs/hardhat-ethers@^2.1.1

contracts/Foo.sol

/* ... */
interface Foo {
  function foo() external returns (uint);
} 

tests/bar.ts

/* ... */
const foo = await smock.fake<Foo>("Foo");
/* ... */

Expected behavior No error

Actual behavior

Error: unable to generate smock spec from contract name.
0x0000000000000000000000000000000000000000 is not a contract account.

System Specs:

kkirka commented 1 year ago

The related hardhat PR: https://github.com/NomicFoundation/hardhat/pull/2916

opticlab commented 1 year ago

It looks like this issue have been fixed on their end.

https://github.com/NomicFoundation/hardhat/pull/3301