Skip to content
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: mocking Diamond proxy schemes #116

Closed
hickscorp opened this issue Jun 2, 2022 · 4 comments
Closed

feat request: mocking Diamond proxy schemes #116

hickscorp opened this issue Jun 2, 2022 · 4 comments

Comments

@hickscorp
Copy link

hickscorp commented Jun 2, 2022

This is not a bug report - rather it's probably the start of a discuthis ssion, which could either lead to discovering that smock could have new features around the diamond pattern, or a contribution from people who found ways to do things neatly.

Consider the following architecture:

  • You have a contact named Diamond.
  • You have several facets - say FacetA and FacetB.
  • You want to test FacetA, and you don't want to mix concerns from FacetB - in a nutshell, you would like to somehow act as if FacetB would be a separate contract.

At this point, I found myself stuck - because although FacetA and FacetB are split into different contacts, all their methods are in fact accessible through the Diamond contract. I didn't find a way to mock FacetB - and I found myself quite often testing things from the FacetA tests that are relevant to FacetB and reciproquelly.

I think since Diamonds often use libraries for functions that are reused across facets, there could be overlap with #50 ... But it's not always the case. Very often in FacetA.sol there are calls such as FacetB(address(this)).someFunction() - and it's not something that smock can help with unfortunatelly.

Can we maybe brainstorm a bit - it might be that I am missing something obvious here - but if not, I think it would be of great help to think about how smock could be improved to help with the diamond pattern.

One of the solution I found which would potentially work, would be to have some facets duplicated just for tests... But that would require quite some boilerplate written in solidity all the time - for example having FacetBMock.sol have a fallback() function which would record all calls so that they could be inspected by the typescript test - return values wouldn't work though.

Another option would be to allow smock to "connect" to an existing address... For example the flow would look like:

  • Deploy diamond with only FacetA.
  • Create a mock of FacetB (Eg smock.mock('FacetB')) and perform a diamondCut` to set it on the diamond.

In case it helps gathering ideas: this is a stack overflow post I've made regarding this particular topic.

@wei3erHase
Copy link
Member

hi @hickscorp,
could you provide a basic example within the smock repo of a diamond deployment and the expected behaviour?
we're not very experienced with proxies and i'm afraid i do not totally understand how the feature would work.
if you can include the required packages and some test contracts, i can help you to develop the tests and add it as a bounty to develop

@wei3erHase wei3erHase changed the title Feature Request / Advice Request: Mocking Diamonds feat request: mocking Diamond proxy schemes Jun 17, 2022
@hickscorp
Copy link
Author

I will!

@hickscorp
Copy link
Author

@wei3erHase happy to team up together today if you have a bit of time. We could get clean requirements written together?

@hickscorp
Copy link
Author

I made a repository which has a README explaining the specs: https://github.com/hickscorp/smock-diamond-showcase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants