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

CCQ: EVM Library and Demo Contract #3425

Merged
merged 11 commits into from
Oct 26, 2023
Merged

Conversation

bruce-riley
Copy link
Contributor

@bruce-riley bruce-riley commented Oct 4, 2023

This PR adds the EVM on chain library used to parse query responses.

This PR is not dependent on any of the other CCQ PRs and can be merged as soon as it is approved.

Copy link
Collaborator

@SEJeff SEJeff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully you don't feel like I'm nitpicking you to death, but here we go sir...

Please use forge fmt to make the spacing and style consistent.

It would be really nice to ship demo contracts good test coverage as these are the contracts people are going to copy and paste if I understand correctly.

Also, in QueryDemo.sol, the assertions that cause reverts are mostly all require(condition, "string explaining the problem") whereas in QueryResponse.sol, they're mostly custom errors. When dealing with the custom errors, solidity uses the first 4 bytes of the selector hash for the custom errors. When using the require syntax with a string, the entire string stays in memory and has to be returned. So using custom errors tends to be much more efficient gas wise and often also results in cleaner code. Whichever style you choose to use, try to be somewhat consistent where it makes sense.

Lastly, the parsing bits could really use some fuzz tests to ensure things work as expected. If you haven't done that or would like to pair on it I'm more than happy to lend a hand. It's basically the exact same as foundry unit tests, but the unit test functions have arguments (of the things you want to fuzz) and you can use some of the cheatcodes like vm.assume() to guide the fuzzer into being useful.

ethereum/contracts/query/QueryDemo.sol Show resolved Hide resolved
ethereum/contracts/query/QueryDemo.sol Show resolved Hide resolved
ethereum/contracts/query/QueryDemo.sol Outdated Show resolved Hide resolved
ethereum/contracts/query/QueryDemo.sol Outdated Show resolved Hide resolved
ethereum/contracts/query/QueryDemo.sol Outdated Show resolved Hide resolved
ethereum/contracts/query/QueryResponse.sol Outdated Show resolved Hide resolved
ethereum/contracts/query/QueryResponse.sol Show resolved Hide resolved
ethereum/contracts/query/QueryResponse.sol Show resolved Hide resolved
ethereum/contracts/query/QueryResponse.sol Outdated Show resolved Hide resolved
ethereum/forge-test/query/Query.t.sol Outdated Show resolved Hide resolved
bruce-riley and others added 10 commits October 23, 2023 11:12
- Context is generally a worthless import
- Ownable is totally unused and a worthless import
To follow standard forge testing practice, you use the same filename
for a test contract as for the file it is testing, but make the
extension .t.sol.
By moving the structs out of the abstract contract, you can use them
directly in any contract that imports QueryResponse.sol *without*
requiring that contract to inherit from the QueryResponse contract. This
seems to work much better with forge's coverage tooling.
Instead of the test contract inheriting directly from the QueryResponse
contract, it instantiates an instance of it and uses that for the
testing. This seems to work much nicer with the forge coverage tools.

With this commit, the coverage for QueryResponse shows 85.1% line
coverage, 100% function coverage, and 50% branch coverage.
If you don't do this, in the tests you have to do:

    vm.expectRevert(bytes4(keccak256("UnsupportedQueryType()")));

Whereas with this change, you can simply import the contract and do:

    vm.expectRevert(UnsupportedQueryType.selector);
* Gas bad
* Natspec updates
* Some address(0) checks in the constructor
* Use custom errors in place of require() to match the error handling
style overall of QueryResponse.
@bruce-riley bruce-riley force-pushed the CCQ/EVM_Library_and_Demo_contract branch from 47a182c to 634c549 Compare October 23, 2023 16:12
@evan-gray evan-gray merged commit 5afd9ea into main Oct 26, 2023
22 checks passed
@evan-gray evan-gray deleted the CCQ/EVM_Library_and_Demo_contract branch October 26, 2023 16:59
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

Successfully merging this pull request may close these issues.

4 participants