Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't enforce no-leading-zeros #55

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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