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

Make some of internal API public so that other crates can build on top of mockall #318

Open
taminomara opened this issue Jul 26, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@taminomara
Copy link

TLDR: I'm writing a crate that will allow mocking ethereum smart contracts, and I want it to work nicely with mockall. For that, I'd like to request making SeqHandle a part of official public API.

Longer explanation.

So, ethereum contracts are like structs (with data and methods) that live in a blockchain. I'm writing a crate that will allow mocking them without using an actual chain. The idea is that you create a mock blockchain and deploy mock contracts onto it. When you deploy a contract, you get an object for setting up expectations. Since we use mockall quite extensively in our projects, I've decided to mirror its API in this object:

let chain = mock_chain();

let contract = chain.deploy_contract(...);
contract.expect_call("MethodA")
    .once()
    .with(...)
    .returning(...);

Now I want to implement in_sequence, and I want it to work with mockall's native SeqHandle. This will allow creating sequences that combine calls to contracts and to normal mocked traits and functions.

@asomers asomers added the enhancement New feature or request label Jul 26, 2021
@asomers
Copy link
Owner

asomers commented Jul 26, 2021

Can you give an example of how you would use SeqHandle?

@taminomara
Copy link
Author

I suppose I'd use it the same way it is used by the generated code. I.e., my struct that represents mocked contract will have in_sequence method, which takes a Sequence, generates a SeqHandle and stores it. Then, whenever and expectation is satisfied or verified, I'll call satisfy or verify method on the stored handle.

@asomers
Copy link
Owner

asomers commented Jul 26, 2021

To help me understand, could you provide a code sample, even one that doesn't compile?

@taminomara
Copy link
Author

Sorry, was away for some time.

Here's an example of our crate's API when used with sequences: https://github.com/gnosis/ethcontract-rs/blob/main/ethcontract-mock/src/test/mod.rs#L118

Specifically, we save mockall's sequence in our code, then we verify and satisfy it when contract methods are called.

@asomers
Copy link
Owner

asomers commented Aug 16, 2021

It looks like you've reimplemented almost all of Mockall, keeping only Sequence, one of the smallest components. Correct? If so, I don't think that's sufficient reason to publicize Sequence's internal API. If I do that, then I would be committed to keeping it stable.

@taminomara
Copy link
Author

I mean, not exactly. I've manually implemented the same code for smart contracts that mockall would generate for traits and structs. Thus, it uses this semi-public API for generated code. And I'd like it to be interoperable with mockall's Sequence. Otherwise, I'll have to roll my own Sequence and loose the entire point of re-implementing mockall's interface.

@asomers
Copy link
Owner

asomers commented Aug 17, 2021

What is the point of reimplementing all of Mockall's generated code, anyway? Are you trying to mix calls to the same Sequence objects from both generated code and your own custom code?

@taminomara
Copy link
Author

Yes, that's exactly what I'm doing.

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

No branches or pull requests

2 participants