diff --git a/tests/test_quantity.nim b/tests/test_quantity.nim index beb2481..e29fcdb 100644 --- a/tests/test_quantity.nim +++ b/tests/test_quantity.nim @@ -23,8 +23,10 @@ suite "JSON-RPC Quantity": resUInt256Ref[] == validQuantity.u256 test "Invalid Quantity/UInt256/ref UInt256": + # TODO once https://github.com/status-im/nimbus-eth2/pull/3850 addressed, + # re-add "0x0400" test case as invalid. for invalidStr in [ - "", "1234", "01234", "x1234", "0x", "0x0400", "ff"]: + "", "1234", "01234", "x1234", "0x", "ff"]: template checkInvalids(typeName: untyped) = var resQuantity: `typeName` try: diff --git a/web3/conversions.nim b/web3/conversions.nim index f4f4a44..fa59846 100644 --- a/web3/conversions.nim +++ b/web3/conversions.nim @@ -21,7 +21,13 @@ template invalidQuantityPrefix(s: string): bool = # # strutils.parseHexStr treats 0x as optional otherwise. UInt256.parse treats # standalone "0x" as valid input. - (not s.startsWith "0x") or s == "0x" or (s != "0x0" and s.startsWith "0x0") + + # TODO https://github.com/status-im/nimbus-eth2/pull/3850 + # requiring 0x prefis is okay, but can't yet enforce no-leading-zeros + when false: + (not s.startsWith "0x") or s == "0x" or (s != "0x0" and s.startsWith "0x0") + else: + (not s.startsWith "0x") or s == "0x" func `%`*(n: Int256|UInt256): JsonNode = %("0x" & n.toHex)