From 731bdfe90778a6ed42c890db3eb2a77c4a663d1c Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 12 Jul 2022 09:31:53 +0000 Subject: [PATCH] don't enforce no-leading-zeros (#55) --- tests/test_quantity.nim | 4 +++- web3/conversions.nim | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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)