Skip to content

Commit

Permalink
move RPCMethod to type.js and only check one block for error catching.
Browse files Browse the repository at this point in the history
  • Loading branch information
carmen0208 committed Dec 20, 2024
1 parent f4b065d commit e3c6780
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/client/src/rpc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BIGINT_0, bigIntToHex, bytesToHex, intToHex } from '@ethereumjs/util'
import { INTERNAL_ERROR, INVALID_BLOCK, INVALID_PARAMS } from './error-code.js'

import type { Chain } from '../blockchain/index.js'
import type { RPCMethod } from './types.js'
import type { Block } from '@ethereumjs/block'
import type { JSONRPCTx, TypedTransaction } from '@ethereumjs/tx'

Expand All @@ -13,7 +14,7 @@ type RPCError = {
data?: string
}

export function callWithStackTrace(handler: Function, debug: boolean): (...args: any) => any {
export function callWithStackTrace(handler: Function, debug: boolean): RPCMethod {
return async (...args: any) => {
try {
const res = await handler(...args)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/rpc/modules/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Admin {
* Returns information about the currently running node.
* see for reference: https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-admin#admin_peers
*/
nodeInfo() {
async nodeInfo() {
const rlpxInfo = this._client.config.server!.getRlpxInfo()
const { enode, id, ip, listenAddr, ports } = rlpxInfo
const { discovery, listener } = ports
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/rpc/modules/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Web3 {
* Returns the current client version
* @param params An empty array
*/
clientVersion() {
async clientVersion() {
return getClientVersion()
}

Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/rpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ export function toRPCTx(t: TxResult): RPCTx {
t.to !== null && (rpcTx.to = t.to)
return rpcTx
}

export type RPCMethod = (...params: any) => any
2 changes: 1 addition & 1 deletion packages/client/src/rpc/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INVALID_PARAMS } from './error-code.js'

type RPCMethod = (params: any[]) => any
import type { RPCMethod } from './types.js'

/**
* middleware for parameters validation
Expand Down
9 changes: 3 additions & 6 deletions packages/client/test/rpc/debug/setHead.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe(method, async () => {
validateBlocks: true,
validateConsensus: false,
})
const blocks = await blockchain.getBlocks(0, 6, 0, false)
const exec = await testSetup(blockchain)
await exec.run()
const newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
Expand All @@ -82,10 +81,8 @@ describe(method, async () => {
const manager = createManager(client)
const rpc = getRPCClient(startRPC(manager.getMethods()))

for (let i = 0; i < blocks.length; i++) {
const result = await rpc.request(method, [`0x${i}`])
assert.equal(result.error.code, -32603)
assert.equal(result.error.message, 'Internal error')
}
const result = await rpc.request(method, ['0x1'])
assert.equal(result.error.code, -32603)
assert.equal(result.error.message, 'Internal error')
})
})

0 comments on commit e3c6780

Please sign in to comment.