From d70d07366fcc9ed2a750a5427af9d210c486f344 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Mon, 19 Nov 2018 12:43:16 -0800 Subject: Tests for Static Bytes --- packages/utils/src/abi_encoder/evm_data_types.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_encoder/evm_data_types.ts b/packages/utils/src/abi_encoder/evm_data_types.ts index 38878f63e..ff1bc594d 100644 --- a/packages/utils/src/abi_encoder/evm_data_types.ts +++ b/packages/utils/src/abi_encoder/evm_data_types.ts @@ -270,6 +270,10 @@ export class Byte extends PayloadDataType { } public encodeValue(value: string | Buffer): Buffer { + // Sanity check if string + if (typeof value === 'string' && value.startsWith('0x') === false) { + throw new Error(`Tried to encode non-hex value. Value must inlcude '0x' prefix.`); + } // Convert value into a buffer and do bounds checking const valueBuf = ethUtil.toBuffer(value); if (valueBuf.byteLength > this.width) { -- cgit v1.2.3