From e27114e22984a2bac624ec2683b72740a947747b Mon Sep 17 00:00:00 2001 From: bomanaps Date: Mon, 29 Jun 2026 12:01:19 +0100 Subject: [PATCH] Add net_listening and net_peerCount --- src/eth/client.yaml | 27 +++++++++++++++++ tests/net_listening/get-listening.io | 3 ++ tests/net_peerCount/get-peer-count.io | 3 ++ tools/testgen/generators.go | 42 +++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 tests/net_listening/get-listening.io create mode 100644 tests/net_peerCount/get-peer-count.io diff --git a/src/eth/client.yaml b/src/eth/client.yaml index 27a20dafe..2158b187a 100644 --- a/src/eth/client.yaml +++ b/src/eth/client.yaml @@ -133,3 +133,30 @@ result: name: Network ID value: '1' +- name: net_listening + summary: Returns true if the client is actively listening for network connections. + params: [] + result: + name: Listening + schema: + title: Listening + type: boolean + examples: + - name: net_listening example + params: [] + result: + name: Listening + value: true +- name: net_peerCount + summary: Returns the number of peers currently connected to the client. + params: [] + result: + name: Peer count + schema: + $ref: '#/components/schemas/uint' + examples: + - name: net_peerCount example + params: [] + result: + name: Peer count + value: '0x2' diff --git a/tests/net_listening/get-listening.io b/tests/net_listening/get-listening.io new file mode 100644 index 000000000..a15f7be16 --- /dev/null +++ b/tests/net_listening/get-listening.io @@ -0,0 +1,3 @@ +// Calls net_listening to check whether the client is listening for network connections. +>> {"jsonrpc":"2.0","id":1,"method":"net_listening"} +<< {"jsonrpc":"2.0","id":1,"result":true} diff --git a/tests/net_peerCount/get-peer-count.io b/tests/net_peerCount/get-peer-count.io new file mode 100644 index 000000000..45931fa85 --- /dev/null +++ b/tests/net_peerCount/get-peer-count.io @@ -0,0 +1,3 @@ +// Calls net_peerCount to retrieve the number of connected peers. The test client runs without peers, so the expected value is zero. +>> {"jsonrpc":"2.0","id":1,"method":"net_peerCount"} +<< {"jsonrpc":"2.0","id":1,"result":"0x0"} diff --git a/tools/testgen/generators.go b/tools/testgen/generators.go index 71007a764..3ffed3aba 100644 --- a/tools/testgen/generators.go +++ b/tools/testgen/generators.go @@ -98,6 +98,8 @@ var AllMethods = []MethodTests{ EthConfig, EthCapabilities, NetVersion, + NetListening, + NetPeerCount, TestingBuildBlockV1, TxpoolStatus, TxpoolContent, @@ -2452,6 +2454,46 @@ var NetVersion = MethodTests{ }, } +var NetListening = MethodTests{ + "net_listening", + []Test{ + { + Name: "get-listening", + About: "Calls net_listening to check whether the client is listening for network connections.", + Run: func(ctx context.Context, t *T) error { + var got bool + if err := t.rpc.CallContext(ctx, &got, "net_listening"); err != nil { + return err + } + if !got { + return fmt.Errorf("net_listening returned false, want true") + } + return nil + }, + }, + }, +} + +var NetPeerCount = MethodTests{ + "net_peerCount", + []Test{ + { + Name: "get-peer-count", + About: "Calls net_peerCount to retrieve the number of connected peers. The test client runs without peers, so the expected value is zero.", + Run: func(ctx context.Context, t *T) error { + var got hexutil.Uint + if err := t.rpc.CallContext(ctx, &got, "net_peerCount"); err != nil { + return err + } + if got != 0 { + return fmt.Errorf("unexpected peer count (got: %d, want: 0)", got) + } + return nil + }, + }, + }, +} + // validateBuildBlockV1Response validates the common parts of a testing_buildBlockV1 response. func validateBuildBlockV1Response( t *T,