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

Partially matching call arguments #14

Open
josojo opened this issue Jul 27, 2019 · 8 comments
Open

Partially matching call arguments #14

josojo opened this issue Jul 27, 2019 · 8 comments
Assignees

Comments

@josojo
Copy link
Contributor

josojo commented Jul 27, 2019

Background
The Gnosis MockContract is a smart contract enabling developers to quickly mock contract interactions for unit tests.
It enables developers to

  • Make dependent contracts return predefined values for different methods and arguments
  • Simulate exceptions such as revert and outOfGas
  • Assert on how often a dependency is called

The MockContract facilitates these features without requiring any separate test contracts.
Check out the repo: https://github.com/gnosis/mock-contract

Task
Extend the functionality of the MockContract to partially matching arguments.

Acceptance criteria

  • Develop a framework allowing developers to define partially matching calldata for specific methods. 
Defining partially matched call data should look similar to:
const particallyMatchedCalldata = contract.methods.methodName(
   accounts[0], ANY, ..., ANY
   ).encodeABI()

Here, ANY would be some sort of constant defined in the smart contract.

  • Write the logic for the MockContract to expose predefined returns to the partially matched calldata. 
It is expected that the following functions for partially matched calldata are provided:
	function givenPartialCalldataReturn(bytes calldata call, bytes calldata response) external;
	function givenPartialCalldataReturnBool(bytes calldata call, bool response) external;
	function givenPartialCalldataReturnUint(bytes calldata call, uint response) external;
	function givenPartialCalldataReturnAddress(bytes calldata call, address response) external;

	function givenPartialCalldataRevert(bytes calldata call) external;
	function givenPartialCalldataRevertWithMessage(bytes calldata call, string calldata message) external;
	function givenPartialCalldataRunOutOfGas(bytes calldata call) external;

They should enable the same functionality on partially matching calldata as the current respective functions with the same function names, but without the word "Partial".

  • Make sure the invocation count functions are still returning the expected numbers
:
       function invocationCount() external returns (uint);
       function invocationCountForMethod(bytes calldata method) external returns (uint);
       function invocationCountForCalldata(bytes calldata call) external returns (uint);
  • Current naming conventions need to be preseved
  • All functionality must have 100 % line and branch coverage
  • The solidity style guide must be considered and code must be linted

Payout:
0.5 ETH
Additional GNO can be tipped according to the level of technical implementation

@fleupold
Copy link
Contributor

Looks really good! A few small comments.

The MockContract allows for all of that without having to write a separate test contract each time.

This sentence could be slightly smoother, but I don't have a concrete suggestion either. Maybe @bh2smith ?

After the ANY example, we might want to add that ANY can be a e.g. a constant defined on the smart contract.

Should we also make the interface we expect to be implemented explicit?

function givenPartialCalldataReturn(bytes calldata call, bytes calldata response) external;
...

@josojo
Copy link
Contributor Author

josojo commented Jul 29, 2019

The MockContract allows for all of that without having to write a separate test contract each time.

Maybe like this?
The MockContract facilitates these features without requiring any separate test contracts.

Should we also make the interface we expect to be implemented explicit?

done

@josojo
Copy link
Contributor Author

josojo commented Jul 29, 2019

After the ANY example, we might want to add that ANY can be a e.g. a constant defined on the smart contract.

what is the value of making ANY also a constant? Probably, I do not understand.

@fleupold
Copy link
Contributor

what is the value of making ANY also a constant?

ANY has to be defined somewhere, otherwise the code wouldn't compile. My suggestion would be to have it some magic value on the smart contract.

@bh2smith
Copy link

bh2smith commented Jul 29, 2019

The MockContract facilitates these features without requiring any separate test contracts.

Much better!

@GnosisEcosystemFund GnosisEcosystemFund changed the title [Draft Task 1] Partially matching call arguments Partially matching call arguments Jul 31, 2019
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 0.5 ETH (106.07 USD @ $212.14/ETH) attached to it as part of the Gnosis fund.

@gitcoinbot
Copy link

gitcoinbot commented Aug 11, 2019

Issue Status: 1. Open 2. Cancelled


Workers have applied to start work.

These users each claimed they can complete the work by 2 years, 4 months ago.
Please review their action plans below:

1) mikehathaway has applied to start work (Funders only: approve worker | reject worker).

I will use Truffle Suite tools to run a local Eth node and rapidly prototype a smart contract that can be used for mocking Gnosis contract interactions. Following completion of a contract that meets basic specifications, I will seek to iteratively improve it.

Learn more on the Gitcoin Issue Details page.

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Cancelled


The funding of 0.5 ETH (67.09 USD @ $134.18/ETH) attached to this issue has been cancelled by the bounty submitter

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

5 participants