-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat request: adding support for mocking libraries #50
Comments
Hey @ashhanai , it's great to see that people are actually using Smock v2! Your proposal sounds super interesting, could you please provide a test that would illustrate better the use case? |
Hi @0xGorilla, sure. Use caseCreate a token abstraction and pack ERC20, ERC721 & ERC1155 into one struct Token. Implement library, that uses Token struct and defines functions for transfer and approve transfers of underlying ERC20 / 721 / 1155 tokens. Use this token to eliminate unnecessary type check every time transfer / approval should occur. TestMy contract is transferring tokens via this abstraction and I want to test, that it calls the right function of the library (library is tester separately, so just the call check is enough). The issue here is that my contract is linking the library and using it like this: I hope I made the use case more understandable. |
I meant forking this repo and creating a real test (that would fail), from there I will grab the test and try to make it pass. Is that possible? From there it will be easier to develop a solution |
@0xGorilla this is related to our plan to add mocking for libraries in general, which requires that deeper rewrite we discussed. It's definitely a huge value add but will take some effort. |
This is still not solved, but at least right now you can deploy a mock that uses a library, check out the tests of #68 |
I've been using smock a whole lot lately and have been also working with the Ethereum Diamonds (https://eips.ethereum.org/EIPS/eip-2535). Diamonds use a lot of libraries and being able to mock a library would make unit testing Diamond Facet's 1000x easier. |
First of all, I'm completely mind blown by what Now - mocking libraries - this is a really tricky topic. Solidity libraries are weird beasts...
Now regarding 2 - during this step, I discovered a few things:
To finish - I might have forgotten a few things here - I would really like that |
Came across this issue today, it'd be great to have support for this! We have the exact same use case as @ashhanai |
Make it possible to mock libraries in contracts.
Example:
I am using my own library Lib with struct Lib.Str in my contract Con.
using Lib for Lib.Str;
My Lib has few methods which works with Lib.Str:
function foo(Lib.Str memory _str, uint256 _amount) external
I am calling this functions in my contract like this:
str.foo(10);
I would really use mocking this library and be able to see, if my contract (which is using this library) called function
foo
, how many times and so on.The text was updated successfully, but these errors were encountered: