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

Remove error field from AccessListResult #135

Merged
merged 2 commits into from
Feb 29, 2024
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
61 changes: 58 additions & 3 deletions tests/test_execution_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,59 @@ type
const
inputPath = "tests/execution-apis/tests"

{.push raises: [].}

func compareValue(lhs, rhs: JsonValueRef): bool

func compareObject(lhs, rhs: JsonValueRef): bool =
# assume lhs.len > rhs.len
# null field and no field are treated equals
for k, v in lhs.objVal:
let rhsVal = rhs.objVal.getOrDefault(k, nil)
if rhsVal.isNil:
if v.kind != JsonValueKind.Null:
return false
else:
continue
if not compareValue(rhsVal, v):
return false
true

func compareValue(lhs, rhs: JsonValueRef): bool =
if lhs.isNil and rhs.isNil:
return true

if not lhs.isNil and rhs.isNil:
return false

if lhs.isNil and not rhs.isNil:
return false

if lhs.kind != rhs.kind:
return false

case lhs.kind
of JsonValueKind.String:
lhs.strVal == rhs.strVal
of JsonValueKind.Number:
lhs.numVal == rhs.numVal
of JsonValueKind.Object:
if lhs.objVal.len >= rhs.objVal.len:
compareObject(lhs, rhs)
else:
compareObject(rhs, lhs)
of JsonValueKind.Array:
if lhs.arrayVal.len != rhs.arrayVal.len:
return false
for i, x in lhs.arrayVal:
if not compareValue(x, rhs.arrayVal[i]):
return false
true
of JsonValueKind.Bool:
lhs.boolVal == rhs.boolVal
of JsonValueKind.Null:
true

func strip(line: string): string =
return line[3..^1]

Expand All @@ -28,7 +81,7 @@ func toTx(req: RequestRx): RequestTx =
params: req.params.toTx,
)

proc extractTest(fileName: string): TestData =
proc extractTest(fileName: string): TestData {.raises: [IOError, SerializationError].} =
let
lines = readFile(fileName).split("\n")
input = lines[0].strip()
Expand All @@ -40,7 +93,7 @@ proc extractTest(fileName: string): TestData =
output: JrpcSys.decode(output, ResponseRx),
)

proc extractTests(): seq[TestData] =
proc extractTests(): seq[TestData] {.raises: [OSError, IOError, SerializationError].} =
for fileName in walkDirRec(inputPath):
if fileName.endsWith(".io"):
result.add(fileName.extractTest())
Expand All @@ -62,7 +115,7 @@ proc callWithParams(client: RpcClient, data: TestData): Future[bool] {.async.} =
let wantVal = JrpcConv.decode(res.result.string, JsonValueRef[string])
let getVal = JrpcConv.decode(resJson.string, JsonValueRef[string])

if wantVal != getVal:
if not compareValue(wantVal, getVal):
debugEcho data.file
debugEcho "EXPECT: ", res.result
debugEcho "GET: ", resJson.string
Expand Down Expand Up @@ -131,3 +184,5 @@ suite "Test eth api":

waitFor srv.stop()
waitFor srv.closeWait()

{.pop.}
11 changes: 8 additions & 3 deletions tests/test_json_marshalling.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# nim-web3
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -213,9 +213,14 @@ suite "JSON-RPC Quantity":
let a = JrpcConv.decode("\"0x016345785d8a0000\"", Quantity)
check a.uint64 == 100_000_000_000_000_000'u64
let b = JrpcConv.encode(a)
check b.string == "\"0x16345785d8a0000\""
check b == "\"0x16345785d8a0000\""

let x = JrpcConv.decode("\"0xFFFF_FFFF_FFFF_FFFF\"", Quantity)
check x.uint64 == 0xFFFF_FFFF_FFFF_FFFF_FFFF'u64
let y = JrpcConv.encode(x)
check y.string == "\"0xffffffffffffffff\""
check y == "\"0xffffffffffffffff\""

test "AccessListResult":
var z: AccessListResult
let w = JrpcConv.encode(z)
check w == """{"accessList":[],"gasUsed":"0x0"}"""
4 changes: 2 additions & 2 deletions web3/eth_api_types.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# nim-web3
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -130,7 +130,6 @@ type

AccessListResult* = object
accessList*: seq[AccessTuple]
error*: string
gasUsed*: Quantity

TransactionObject* = ref object # A transaction object, or null when no transaction was found:
Expand All @@ -148,6 +147,7 @@ type
v*: Quantity # ECDSA recovery id
r*: UInt256 # ECDSA signature r
s*: UInt256 # ECDSA signature s
yParity*: Option[Quantity] # ECDSA y parity, none for Legacy, same as v for >= Tx2930
`type`*: Option[Quantity] # EIP-2718, with 0x0 for Legacy
chainId*: Option[Quantity] # EIP-159
accessList*: Option[seq[AccessTuple]] # EIP-2930
Expand Down