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

chore: migrate GPv2Signing recoverOrderSigner tests to Foundry #207

Merged
merged 30 commits into from
Aug 15, 2024

Conversation

fedgiac
Copy link
Contributor

@fedgiac fedgiac commented Aug 14, 2024

Description

See title.

test_reverts_for_invalid_signing_schemes has not been migrated because the compiler itself enforces that the signing scheme is valid and there's no way that I know of to force the compiler to give the library a value that doesn't fit the expected input type.

Test Plan

CI.

Related Issues

#120

@fedgiac fedgiac requested a review from a team as a code owner August 14, 2024 12:22
test/libraries/Sign.sol Outdated Show resolved Hide resolved
mfw78
mfw78 previously approved these changes Aug 15, 2024
function test_reverts_for_invalid_signing_schemes() public {
vm.expectRevert();
executor.recoverOrderSignerTest(
defaultOrder(), Sign.Signature({scheme: GPv2Signing.Scheme(uint8(42)), data: hex""})
Copy link
Contributor

@mfw78 mfw78 Aug 15, 2024

Choose a reason for hiding this comment

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

This test isn't achieving it's actual desired outcome as attempting to convert uint8(42) into GPv2Signing.Scheme causes a revert with a panic at this specific point in the test before there's an actual revert on recoverOrderSignerTest, so it seems that this would require a low-level call to by-pass the solidity type checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, you're absolutely right, great find!
My expectation was that expectRevert catches a revert in the next call, but it just catches any revert that follows! So this is a successful test:

vm.expectRevert("test revert");
revert("test revert");

Also, there are valid tests that cannot be compiled, for example:

vm.expectRevert("test revert");
revert("test revert");
return;

Which fails compilation with:

Warning (5740): Unreachable code.
  --> test/GPv2Signing/RecoverOrderSigner.t.sol:54:9:
   |
54 |         return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought a bit about it and it's hard to meaningfully simulate this. We are testing a library, so we can't call something and see a revert because all of this is handled at a compiler level. So I ended up simplifying the test to just revert if a function tries to internally generate an invalid signing scheme. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we think that this value adds? I'd argue that because it can be tested in solidity, and the uint8 conversion of the enum is bound by types within the compiler, it's safe for us to remove this test entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. Test has been removed and PR description has been updated.

@mfw78 mfw78 dismissed their stale review August 15, 2024 12:58

Approved in error

Base automatically changed from migrate-test-signing-calldata-manipulation to main August 15, 2024 13:51
@fedgiac fedgiac requested a review from mfw78 August 15, 2024 14:55
@fedgiac fedgiac merged commit af90c59 into main Aug 15, 2024
9 checks passed
@fedgiac fedgiac deleted the migrate-test-signing-recoverOrderSigner branch August 15, 2024 15:42
@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants