-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix problem with contract out of assets * Add nully value json test * Fix bug with passing null to a few functions * Typesafe U256 parsing * Update readme for the web3 to include runner info * Cleanup commits Strip out unused JSON Update comment Remove echo Added DynamicBytes test More correct naming Remove one extra double check * Add specific object tests * Ensure we cover different status types * Add header comments * Cleanup * Add more tests * Cleanup * Revert docs * Nimpretty file * Fix issue in base stew * Add tests * Sorting * Work on tests * Move items to the correct location * Add TODO * Add all test executables * Work on generating tests * Push latest execution API changes * Work on eth_call test * Fix source type * Latest * Add many more tests * Add more tests * Revert "from" to "source" * Try fix types * Split to types which fail and those which dont * Cleanup * Remove whispher types again * re-remove whisper * Add more eth_api signature * Readding executions-apis submodule * Disable test_execution_api * Nitpick * add handlers * Add last line to handler * Some handler pass * Finally all tests pass * Add the test to all_tests * Consisten style * Turn on submodule downloading in CI * Temporary workaround of get eth_getBlockReceipts for nim 2.0 --------- Co-authored-by: jangko <[email protected]>
- Loading branch information
Showing
11 changed files
with
315 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "tests/execution-apis"] | ||
path = tests/execution-apis | ||
url = https://github.com/ethereum/execution-apis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule execution-apis
added at
cea7ee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# json-rpc | ||
# Copyright (c) 2024 Status Research & Development GmbH | ||
# Licensed under either of | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
# * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
# at your option. | ||
# This file may not be copied, modified, or distributed except according to | ||
# those terms. | ||
|
||
import | ||
stint, | ||
eth/common, | ||
json_rpc/rpcserver, | ||
../../web3/conversions, | ||
../../web3/eth_api_types, | ||
../../web3/primitives as w3 | ||
|
||
type | ||
Hash256 = w3.Hash256 | ||
|
||
proc installHandlers*(server: RpcServer) = | ||
server.rpc("eth_syncing") do(x: JsonString, ) -> bool: | ||
return false | ||
|
||
server.rpc("eth_sendRawTransaction") do(x: JsonString, data: seq[byte]) -> TxHash: | ||
let tx = rlp.decode(data, Transaction) | ||
let h = rlpHash(tx) | ||
return TxHash(h.data) | ||
|
||
server.rpc("eth_getTransactionReceipt") do(x: JsonString, data: TxHash) -> ReceiptObject: | ||
var r: ReceiptObject | ||
if x != "-1".JsonString: | ||
r = JrpcConv.decode(x.string, ReceiptObject) | ||
return r | ||
|
||
server.rpc("eth_getTransactionByHash") do(x: JsonString, data: TxHash) -> TransactionObject: | ||
var tx: TransactionObject | ||
if x != "-1".JsonString: | ||
tx = JrpcConv.decode(x.string, TransactionObject) | ||
return tx | ||
|
||
server.rpc("eth_getTransactionByBlockNumberAndIndex") do(x: JsonString, blockId: RtBlockIdentifier, quantity: Quantity) -> TransactionObject: | ||
var tx: TransactionObject | ||
if x != "-1".JsonString: | ||
tx = JrpcConv.decode(x.string, TransactionObject) | ||
return tx | ||
|
||
server.rpc("eth_getTransactionByBlockHashAndIndex") do(x: JsonString, data: Hash256, quantity: Quantity) -> TransactionObject: | ||
var tx: TransactionObject | ||
if x != "-1".JsonString: | ||
tx = JrpcConv.decode(x.string, TransactionObject) | ||
return tx | ||
|
||
server.rpc("eth_getTransactionCount") do(x: JsonString, data: Address, blockId: RtBlockIdentifier) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
server.rpc("eth_getStorageAt") do(x: JsonString, data: Address, slot: UInt256, blockId: RtBlockIdentifier) -> FixedBytes[32]: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, FixedBytes[32]) | ||
|
||
server.rpc("eth_getProof") do(x: JsonString, address: Address, slots: seq[UInt256], blockId: RtBlockIdentifier) -> ProofResponse: | ||
var p: ProofResponse | ||
if x != "-1".JsonString: | ||
p = JrpcConv.decode(x.string, ProofResponse) | ||
return p | ||
|
||
server.rpc("eth_getCode") do(x: JsonString, data: Address, blockId: RtBlockIdentifier) -> seq[byte]: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, seq[byte]) | ||
|
||
server.rpc("eth_getBlockTransactionCountByNumber") do(x: JsonString, blockId: RtBlockIdentifier) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
server.rpc("eth_getBlockTransactionCountByHash") do(x: JsonString, data: BlockHash) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
when NimMajor >= 2: | ||
server.rpc("eth_getBlockReceipts") do(x: JsonString, blockId: RtBlockIdentifier) -> JsonString: | ||
# TODO: cannot prove obj is not nil | ||
return x | ||
else: | ||
server.rpc("eth_getBlockReceipts") do(x: JsonString, blockId: RtBlockIdentifier) -> Option[seq[ReceiptObject]]: | ||
if x == "null".JsonString: | ||
var n: Option[seq[ReceiptObject]] | ||
return n | ||
if x != "-1".JsonString: | ||
let r = JrpcConv.decode(x.string, seq[ReceiptObject]) | ||
return some(r) | ||
|
||
server.rpc("eth_getBlockByNumber") do(x: JsonString, blockId: RtBlockIdentifier, fullTransactions: bool) -> BlockObject: | ||
var blk: BlockObject | ||
if x != "-1".JsonString: | ||
blk = JrpcConv.decode(x.string, BlockObject) | ||
return blk | ||
|
||
server.rpc("eth_getBlockByHash") do(x: JsonString, data: BlockHash, fullTransactions: bool) -> BlockObject: | ||
var blk: BlockObject | ||
if x != "-1".JsonString: | ||
blk = JrpcConv.decode(x.string, BlockObject) | ||
return blk | ||
|
||
server.rpc("eth_getBalance") do(x: JsonString, data: Address, blockId: RtBlockIdentifier) -> UInt256: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, UInt256) | ||
|
||
server.rpc("eth_feeHistory") do(x: JsonString, blockCount: Quantity, newestBlock: RtBlockIdentifier, rewardPercentiles: Option[seq[float64]]) -> FeeHistoryResult: | ||
var fh: FeeHistoryResult | ||
if x != "-1".JsonString: | ||
fh = JrpcConv.decode(x.string, FeeHistoryResult) | ||
return fh | ||
|
||
server.rpc("eth_estimateGas") do(x: JsonString, call: EthCall) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
server.rpc("eth_createAccessList") do(x: JsonString, call: EthCall, blockId: RtBlockIdentifier) -> AccessListResult: | ||
var z: AccessListResult | ||
if x != "-1".JsonString: | ||
z = JrpcConv.decode(x.string, AccessListResult) | ||
return z | ||
|
||
server.rpc("eth_chainId") do(x: JsonString, ) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
server.rpc("eth_call") do(x: JsonString, call: EthCall, blockId: RtBlockIdentifier) -> seq[byte]: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, seq[byte]) | ||
|
||
server.rpc("eth_blockNumber") do(x: JsonString) -> Quantity: | ||
if x != "-1".JsonString: | ||
result = JrpcConv.decode(x.string, Quantity) | ||
|
||
server.rpc("debug_getRawTransaction") do(x: JsonString, data: TxHash) -> RlpEncodedBytes: | ||
var res: seq[byte] | ||
if x != "-1".JsonString: | ||
res = JrpcConv.decode(x.string, seq[byte]) | ||
return res.RlpEncodedBytes | ||
|
||
server.rpc("debug_getRawReceipts") do(x: JsonString, blockId: RtBlockIdentifier) -> seq[RlpEncodedBytes]: | ||
var res: seq[RlpEncodedBytes] | ||
if x != "-1".JsonString: | ||
res = JrpcConv.decode(x.string, seq[RlpEncodedBytes]) | ||
return res | ||
|
||
server.rpc("debug_getRawHeader") do(x: JsonString, blockId: RtBlockIdentifier) -> RlpEncodedBytes: | ||
var res: seq[byte] | ||
if x != "-1".JsonString: | ||
res = JrpcConv.decode(x.string, seq[byte]) | ||
return res.RlpEncodedBytes | ||
|
||
server.rpc("debug_getRawBlock") do(x: JsonString, blockId: RtBlockIdentifier) -> RlpEncodedBytes: | ||
var res: seq[byte] | ||
if x != "-1".JsonString: | ||
res = JrpcConv.decode(x.string, seq[byte]) | ||
return res.RlpEncodedBytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import | ||
std/[os, strutils], | ||
pkg/unittest2, | ||
chronos, | ||
json_rpc/[rpcclient, rpcserver], | ||
json_rpc/private/jrpc_sys, | ||
../web3/conversions, | ||
./helpers/handlers | ||
|
||
type | ||
TestData = tuple | ||
file: string | ||
input: RequestTx | ||
output: ResponseRx | ||
|
||
const | ||
inputPath = "tests/execution-apis/tests" | ||
|
||
func strip(line: string): string = | ||
return line[3..^1] | ||
|
||
func toTx(req: RequestRx): RequestTx = | ||
RequestTx( | ||
id: Opt.some(req.id), | ||
`method`: req.`method`.get(), | ||
params: req.params.toTx, | ||
) | ||
|
||
proc extractTest(fileName: string): TestData = | ||
let | ||
lines = readFile(fileName).split("\n") | ||
input = lines[0].strip() | ||
output = lines[1].strip() | ||
|
||
return ( | ||
file: fileName, | ||
input: JrpcSys.decode(input, RequestRx).toTx, | ||
output: JrpcSys.decode(output, ResponseRx), | ||
) | ||
|
||
proc extractTests(): seq[TestData] = | ||
for fileName in walkDirRec(inputPath): | ||
if fileName.endsWith(".io"): | ||
result.add(fileName.extractTest()) | ||
|
||
proc callWithParams(client: RpcClient, data: TestData): Future[bool] {.async.} = | ||
let res = data.output | ||
|
||
try: | ||
var params = data.input.params | ||
if data.output.result.string.len > 0: | ||
params.positional.insert(data.output.result, 0) | ||
else: | ||
params.positional.insert("-1".JsonString, 0) | ||
|
||
let resJson = await client.call(data.input.`method`, params) | ||
|
||
if res.result.string.len > 0: | ||
let wantVal = JrpcConv.decode(res.result.string, JsonValueRef[string]) | ||
let getVal = JrpcConv.decode(resJson.string, JsonValueRef[string]) | ||
|
||
if wantVal != getVal: | ||
debugEcho data.file | ||
debugEcho "EXPECT: ", res.result | ||
debugEcho "GET: ", resJson.string | ||
return false | ||
|
||
return true | ||
except SerializationError as exc: | ||
debugEcho data.file | ||
debugEcho exc.formatMsg("xxx") | ||
return false | ||
except CatchableError as exc: | ||
if res.error.isSome: | ||
return true | ||
debugEcho data.file | ||
debugEcho exc.msg | ||
return false | ||
|
||
const allowedToFail = [ | ||
"fee-history.io" # float roundtrip not match | ||
] | ||
|
||
suite "Ethereum execution api": | ||
let testCases = extractTests() | ||
if testCases.len < 1: | ||
raise newException(ValueError, "execution_api tests not found, did you clone?") | ||
|
||
var srv = newRpcHttpServer(["127.0.0.1:0"]) | ||
srv.installHandlers() | ||
srv.start() | ||
|
||
for idx, item in testCases: | ||
let input = item.input | ||
let methodName = input.`method` | ||
|
||
test methodName: | ||
let (_, fileName, ext) = splitFile(item.file) | ||
let client = newRpcHttpClient() | ||
waitFor client.connect("http://" & $srv.localAddress()[0]) | ||
let response = waitFor client.callWithParams(item) | ||
let source = fileName & ext | ||
if source in allowedToFail: | ||
check true | ||
else: | ||
check response | ||
waitFor client.close() | ||
|
||
waitFor srv.stop() | ||
waitFor srv.closeWait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters