Skip to content

Commit

Permalink
Fix SingleOrList parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jan 13, 2024
1 parent 744b4e2 commit 4ab592b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_json_marshalling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,18 @@ suite "JSON-RPC Quantity":
let c = JrpcConv.decode(x, RtBlockIdentifier)
check c.kind == bidNumber
check c.number == 77

let d = JrpcConv.decode("\"10\"", RtBlockIdentifier)
check d.kind == bidAlias
check d.alias == "10"

expect JsonReaderError:
let d = JrpcConv.decode("10", RtBlockIdentifier)
discard d

test "check address or list":
let a = AddressOrList(kind: slkNull)
let x = JrpcConv.encode(a)
let c = JrpcConv.decode(x, AddressOrList)
check c.kind == slkNull

5 changes: 5 additions & 0 deletions web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func valid(hex: string): bool =
if hex.len >= 2:
if hex[0] == '0' and hex[1] in {'x', 'X'}:
start = 2
else:
return false
else:
return false

for i in start..<hex.len:
let x = hex[i]
Expand Down Expand Up @@ -329,6 +333,7 @@ proc readValue*[T](r: var JsonReader[JrpcConv], val: var SingleOrList[T])
r.readValue(val.list)
of JsonValueKind.Null:
val = SingleOrList[T](kind: slkNull)
r.parseNull()
else:
r.raiseUnexpectedValue("TopicOrList unexpected token kind =" & $tok)

Expand Down

0 comments on commit 4ab592b

Please sign in to comment.