diff --git a/tests/ethprocs.nim b/tests/ethprocs.nim index 215d097..d54ea9c 100644 --- a/tests/ethprocs.nim +++ b/tests/ethprocs.nim @@ -1,4 +1,4 @@ -import ../rpcserver, nimcrypto, json, stint, strutils, ethtypes, stintjson +import ../rpcserver, nimcrypto, json, stint, strutils, ethtypes, stintjson, ethutils #[ For details on available RPC calls, see: https://github.com/ethereum/wiki/wiki/JSON-RPC @@ -38,10 +38,10 @@ proc addEthRpcs*(server: RpcServer) = ## Returns the SHA3 result of the given string. # TODO: Capture error on malformed input var rawData: seq[byte] - if data.len > 2 and data[0] == '0' and data[1] in ['x', 'X']: + if data.validateHexData: rawData = data[2..data.high].fromHex else: - rawData = data.fromHex + raise newException(ValueError, "Invalid hex format") # data will have 0x prefix result = "0x" & $keccak_256.digest(rawData)