From 0270777cfc1979e2b802c21fca7d7333e1d2e34d Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Thu, 19 Sep 2019 05:41:00 -0400 Subject: [PATCH] `@0x/contracts-test-utils`: Add `hexHash()` to `hex_utils`. --- contracts/test-utils/CHANGELOG.json | 4 ++++ contracts/test-utils/src/hex_utils.ts | 7 +++++++ contracts/test-utils/src/index.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contracts/test-utils/CHANGELOG.json b/contracts/test-utils/CHANGELOG.json index 875f1fbc30..8496757a6f 100644 --- a/contracts/test-utils/CHANGELOG.json +++ b/contracts/test-utils/CHANGELOG.json @@ -86,6 +86,10 @@ "note": "Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()`", "pr": 2155 }, + { + "note": "Add `hexHash()` to `hex_utils`", + "pr": 2155 + }, { "note": "Add `shortZip()` to `lang_utils.ts`", "pr": 2155 diff --git a/contracts/test-utils/src/hex_utils.ts b/contracts/test-utils/src/hex_utils.ts index 05b7a9c781..007bbf9bd5 100644 --- a/contracts/test-utils/src/hex_utils.ts +++ b/contracts/test-utils/src/hex_utils.ts @@ -58,6 +58,13 @@ export function hexSlice(n: Numberish, start: number, end?: number): string { return '0x'.concat(hex.substring(sliceStart, sliceEnd)); } +/** + * Get the keccak hash of some data. + */ +export function hexHash(n: Numberish): string { + return ethUtil.bufferToHex(ethUtil.sha3(ethUtil.toBuffer(toHex(n)))); + } + /** * Convert a string, a number, or a BigNumber into a hex string. * Works with negative numbers, as well. diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 7df55bf89a..bdac824e23 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -28,7 +28,16 @@ export { bytes32Values, testCombinatoriallyWithReferenceFunc, uint256Values } fr export { TransactionFactory } from './transaction_factory'; export { MutatorContractFunction, TransactionHelper } from './transaction_helper'; export { testWithReferenceFuncAsync } from './test_with_reference'; -export { hexConcat, hexLeftPad, hexInvert, hexSlice, hexRandom, hexRightPad, toHex } from './hex_utils'; +export { + hexConcat, + hexHash, + hexLeftPad, + hexInvert, + hexSlice, + hexRandom, + hexRightPad, + toHex, +} from './hex_utils'; export { BatchMatchOrder, ContractName,