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

Add TypedDataUtils.eip712Hash unit tests #173

Merged
merged 4 commits into from
Aug 16, 2021
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Aug 11, 2021

Unit tests have been added for TypedDataUtils.eip712Hash. These tests don't exhaustively check all possible inputs because there are a lot, and they're just passed along to hashStruct. So the hashStruct tests should catch any input-specific changes. Outside of behaviour internal to hashStruct, all of the behaviour should be covered by these tests.

Any calls to eip712Hash in the older signature tests have been removed, as they are now redundant.

@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 11, 2021

This depends upon #172

@Gudahtt Gudahtt changed the base branch from add-sanitize-data-tests to main August 11, 2021 23:58
@Gudahtt Gudahtt marked this pull request as ready for review August 11, 2021 23:58
@Gudahtt Gudahtt requested a review from a team as a code owner August 11, 2021 23:58
@Gudahtt Gudahtt changed the title Add eip712Hash unit tests Add TypedDataUtils.eip712Hash unit tests Aug 12, 2021
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

My initial impression here is the same as #170 (review), namely that these tests seem perhaps uselessly redundant. I'm not sure why it wouldn't suffice to check that it makes the expected calls to sanitizeData, hashStruct, and ethUtil.keccak given the possible branches inside the function, and rely on the encodeData tests for testing a wide range of inputs.

Unit tests have been added for `TypedDataUtils.eip712Hash`. These tests
don't exhaustively check all possible inputs because there are a lot,
and they're just passed along to `hashStruct`. So the `hashStruct`
tests should catch any input-specific changes. Outside of behaviour
internal to `hashStruct`, all of the behaviour should be covered by
these tests.

Any calls to `eip712Hash` in the older signature tests have been
removed, as they are now redundant.
@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 16, 2021

This has been rebased to resolve conflicts

@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 16, 2021

I think these tests are mostly devoid of repeats actually! I only included a few sample inputs here. Most of it was focused on behaviour specific to this function, about how it encodes the type header and the data and concatenates them together, with the data being optional and omitted in some circumstances. And the peculiar range of expected inputs, since it will happily accept inputs that are contrary to the input types.

src/index.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt Gudahtt merged commit cc7c89e into main Aug 16, 2021
@Gudahtt Gudahtt deleted the add-eip-712-hash-tests branch August 16, 2021 20:06
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.

2 participants