Skip to content

Commit

Permalink
don't enforce no-leading-zeros (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Jul 12, 2022
1 parent dfa91e3 commit 731bdfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tests/test_quantity.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 731bdfe

Please sign in to comment.