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

🧼 cleaning out ethers from utils/tests/bytes #237

Merged
merged 4 commits into from
May 22, 2023

Conversation

jtfirek
Copy link
Collaborator

@jtfirek jtfirek commented May 21, 2023

@dawsbot ik you like prs to be shorter, but these changes are very simple. I thought it would just be easier to put them in one pr.
Screen Shot 2023-05-21 at 7 03 34 PM

const inputs: ReadonlyArray<BytesLikeWithNumber[]> = [[0, 1]];

inputs.forEach((input) => {
expect(concat(input)).toStrictEqual(ethers.utils.concat(input as any));
expect(concat(input)).toStrictEqual(new Uint8Array([0, 1]));
Copy link
Owner

Choose a reason for hiding this comment

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

Great type improvement ✅

it('should match expected slice - hexadecimal strings', () => {
const hexValues = ['0x123456'];
hexValues.forEach((hexValue) => {
expect(hexDataSlice(hexValue, 0, 2)).toStrictEqual('0x1234');
Copy link
Owner

Choose a reason for hiding this comment

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

I think your IDE is missing critical information eslint integration

Screenshot 2023-05-21 at 8 18 52 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dawsbot mmmm trying to replicate this on my machine. I'll just be careful for now till I have time to git this linter in my IDE on my own time.

expect(() => hexlify(value as BytesLike)).toThrow(
'invalid hexlify value',
);
expect(() => hexlify(value as BytesLike)).toThrow('invalid hexlify value');
Copy link
Owner

Choose a reason for hiding this comment

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

Try to never type-cast like this. Instead we should prefer typing at the point of defining the value. Here's why:

https://www.typescriptlang.org/play?#code/C4TwDgpgBA4g9nAJlAvFA3gKCjqBDALimACcBXCTAX00wGM4A7AZ2HwPiVQ0OPIgA0UAEZEAZngA2zCDQYs2w7ul6kKQ0VAnTZ+ZrASIA3EA

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok! so as a general rule of thumb never bypass the type checker.

@dawsbot dawsbot merged commit 962f5ab into dawsbot:master May 22, 2023
1 of 7 checks passed
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.

None yet

2 participants