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

🧪 Use toUtf8Bytes to fix some keccak256 tests #164

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/utils/tests/keccak256.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { utils } from 'ethers';
import type { BytesLike } from './../bytes';
import { keccak256 } from './../keccak256';
import { toUtf8Bytes } from './../to-utf8-bytes';

/**
*
Expand All @@ -11,6 +12,7 @@ function testKeccak256(inputs: Array<BytesLike>) {
expect(keccak256(input)).toBe(utils.keccak256(input));
});
}

describe('keccak256', () => {
it('should match ethers.js hex strings', () => {
const inputs = [
Expand All @@ -24,21 +26,25 @@ describe('keccak256', () => {
const inputs = [[2, 182, 145], [0, 16, 255], [0x12, 0x34], [0x12]];
testKeccak256(inputs);
});
// it('should match ethers.js numbers', () => {
// const inputs = [23874234, 123346, 12395712];
// testKeccak256(inputs);
// });
// it('should match ethers.js strings', () => {
// const inputs = [
// 'essential-eth',
// 'firstText',
// 'secondString',
// 'example1',
// '2934823',
// 'true',
// ];
// testKeccak256(inputs);
// });

it('should match ethers.js numbers', () => {
const inputs = [23874234, 123346, 12395712].map((n) =>
toUtf8Bytes(n.toString()),
);
testKeccak256(inputs);
});

it('should match ethers.js strings', () => {
const inputs = [
'essential-eth',
'firstText',
'secondString',
'example1',
'2934823',
'true',
].map(toUtf8Bytes);
testKeccak256(inputs);
});
// it('should match ethers.js bytes (dynamic size) & BytesLike', () => {
// const inputs = [
// [115, 101, 99, 114, 101, 116],
Expand Down