Skip to content

Commit

Permalink
Use toUtf8Bytes to fix some keccak256 tests (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
larskarbo committed Sep 12, 2022
1 parent 9218c65 commit 91e0434
Showing 1 changed file with 21 additions and 15 deletions.
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

0 comments on commit 91e0434

Please sign in to comment.