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 encode data tests #164

Merged
merged 4 commits into from
Aug 11, 2021
Merged

Add encode data tests #164

merged 4 commits into from
Aug 11, 2021

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jul 27, 2021

The function TypedDataUtils.encodeData has been thoroughly tested with all novel inputs I could think of. Each supported version (V3 and V4) have been tested independently with each input. There are also tests for each input that should have an identical encoding between V3 and V4, and each that should have non-matching signatures.

The structure of the tests is explained in a large inline comment at the start of the describe block for TypedDataUtils.encodeData.

The encodeData assertions that accompanied the signature tests have been deleted, as they're now redundant.

@Gudahtt
Copy link
Member Author

Gudahtt commented Jul 27, 2021

This depends upon #152 and #161. This PR is targeted at #161, and the first commit is #152. The second commit represents the actual contents of this PR.

This depends upon #152

@Gudahtt Gudahtt force-pushed the add-encode-data-tests branch 2 times, most recently from 9496871 to ea3dcbb Compare July 28, 2021 00:28
Base automatically changed from migrate-tests-to-jest to main July 30, 2021 17:36
@Gudahtt Gudahtt changed the base branch from main to allow-sign-typed-data-utilties-to-be-called-unbound August 2, 2021 15:18
Base automatically changed from allow-sign-typed-data-utilties-to-be-called-unbound to main August 3, 2021 18:41
@Gudahtt Gudahtt marked this pull request as ready for review August 3, 2021 22:58
@Gudahtt Gudahtt requested a review from a team as a code owner August 3, 2021 22:58
@Gudahtt Gudahtt force-pushed the add-encode-data-tests branch 2 times, most recently from 082f3f5 to b41746f Compare August 6, 2021 17:36
The function `TypedDataUtils.encodeData` has been thoroughly tested
with all novel inputs I could think of. Each supported version (V3 and
V4) have been tested independently with each input. There are also
tests for each input that should have an identical encoding between
V3 and V4, and each that should have non-matching signatures.

The structure of the tests is explained in a large inline comment at
the start of the `describe` block for `TypedDataUtils.encodeData`.

The `encodeData` assertions that accompanied the signature tests have
been deleted, as they're now redundant.
@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 6, 2021

This PR has been updated with more inline comments explaining what the tests are for.

// Reassigned to silence "no-loop-func" ESLint rule
// It was complaining because it saw that `it` and `expect` as "modified variables from the outer scope"
// which can be dangerous to reference in a loop. But they aren't modified in this case, just invoked.
const _expect = expect;
Copy link
Member Author

Choose a reason for hiding this comment

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

I really wish there was some way to silence this false positive. I didn't want to disable the rule for the whole file because it's genuinely useful still, but this is irritating.

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.

Finished a first pass. Overall looks good. I left some inline change requests.

I'm going to do one more pass to confirm that the table is fully covered, and consider whether the inputs are exhaustive or not. Then we should be done here!

src/index.test.ts Outdated Show resolved Hide resolved
src/index.test.ts Outdated Show resolved Hide resolved
),
];

describe('TypedDataUtils.encodeData', function () {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not using arrow functions for the callbacks in this test suite? mocha hangover?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, right 😅
I was just following existing conventions (I think?). Probably better to use arrow functions, but maybe we can do this in one pass later on.

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 3f2c83c into main Aug 11, 2021
@Gudahtt Gudahtt deleted the add-encode-data-tests branch August 11, 2021 23:38
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