defi-wonderland / smock

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

Support viem and Hardhat toolbox #193

Open robercano opened 9 months ago

robercano commented 9 months ago

Is your feature request related to a problem? Please describe. We've decided to switch to viem for our project, and we were previously using Smock for our tests. Unfortunately Smock does not support viem so we will need to drop it for now.

Describe the solution you'd like Having viem support in Smock

Describe alternatives you've considered There are no other libraries out there with the same functionality, so there aren't really any alternatives

Additional context If you'd be open to collaboration I could have a look to understand how much work it would involve, or at least help with the effort. I'm really interested in having this :)

coreyar commented 8 months ago

I'm curious what dependency you have between viem and smock. My assumption is there is no dependency that you would be able to use smock to mock/ fake contracts and still query them with viem.

robercano commented 8 months ago

Hi @coreyar,

As far as I understood Smock uses Ethers.js Contract type for instantiating the mocks/fakes. I couldn't manage to use viem Contracts with Smock, but perhaps I was doing it wrong. Have you tried this combination of Hardhat Toolbox for viem and Smock?

coreyar commented 8 months ago

I haven't but I played around with it but I dug in a bit today and I was able to get it to work here - https://github.com/coreyar/smock-viem-example/blob/main/test/SmockLock.ts#L152

I need to learn more about how smock works but it is at the evm layer hence the dependency on hardhat but not viem or ethers.