From c98f5bb8b80c3c322bd4b09675cb95369a2f5281 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:04:04 +0100 Subject: [PATCH] test: fix failing harness tests --- rpcserver.go | 35 ++++++++++++++++++++++++++++++++++- rpcserverhelp.go | 4 ++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 26366e757d..1b7319e1f8 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -159,6 +159,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "getmininginfo": handleGetMiningInfo, "getnettotals": handleGetNetTotals, "getnetworkhashps": handleGetNetworkHashPS, + "getnetworkinfo": handleGetNetworkInfo, "getnodeaddresses": handleGetNodeAddresses, "getpeerinfo": handleGetPeerInfo, "getrawmempool": handleGetRawMempool, @@ -233,7 +234,6 @@ var rpcUnimplemented = map[string]struct{}{ "estimatepriority": {}, "getchaintips": {}, "getmempoolentry": {}, - "getnetworkinfo": {}, "getwork": {}, "invalidateblock": {}, "preciousblock": {}, @@ -2493,6 +2493,36 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru return hashesPerSec, nil } +// handleGetNetworkInfo implements the getnetworkinfo command. We only return +// the fields that are not related to wallet functionality. +func handleGetNetworkInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { + _, ok := cmd.(*btcjson.GetNetworkInfoCmd) + if !ok { + return nil, &btcjson.RPCError{ + Code: btcjson.ErrRPCInternal.Code, + Message: "Invalid request type", + } + } + + resp := btcjson.GetNetworkInfoResult{ + Version: int32(1000000*appMajor + 10000*appMinor + 100*appPatch), + SubVersion: "", + ProtocolVersion: int32(maxProtocolVersion), + LocalServices: "", + LocalRelay: !cfg.BlocksOnly, + TimeOffset: int64(s.cfg.TimeSource.Offset().Seconds()), + Connections: s.cfg.ConnMgr.ConnectedCount(), + NetworkActive: s.cfg.Listeners != nil, + Networks: nil, + RelayFee: cfg.minRelayTxFee.ToBTC(), + IncrementalFee: cfg.minRelayTxFee.ToBTC(), + LocalAddresses: make([]btcjson.LocalAddressesResult, 0), + Warnings: "get network info response contains mock data", + } + + return &resp, nil +} + // handleGetNodeAddresses implements the getnodeaddresses command. func handleGetNodeAddresses(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { c := cmd.(*btcjson.GetNodeAddressesCmd) @@ -3976,6 +4006,9 @@ func (s *rpcServer) standardCmdResult(cmd *parsedRPCCmd, closeChan <-chan struct } _, ok = rpcUnimplemented[cmd.method] if ok { + f, _ := os.Create("/tmp/unimplemented") + defer f.Close() + fmt.Fprintf(f, "Command %s is unimplemented\n", cmd.method) handler = handleUnimplemented goto handled } diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 8545a76628..f1ca993491 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -461,6 +461,9 @@ var helpDescsEnUS = map[string]string{ "getnettotalsresult-totalbytessent": "Total bytes sent", "getnettotalsresult-timemillis": "Number of milliseconds since 1 Jan 1970 GMT", + // GetNetworkInfo help. + "getnetworkinfo--synopsis": "Returns an object containing various state info regarding P2P networking. Note: this is mock implementation.", + // GetNodeAddressesResult help. "getnodeaddressesresult-time": "Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen", "getnodeaddressesresult-services": "The services offered", @@ -746,6 +749,7 @@ var rpcResultTypes = map[string][]interface{}{ "getmininginfo": {(*btcjson.GetMiningInfoResult)(nil)}, "getnettotals": {(*btcjson.GetNetTotalsResult)(nil)}, "getnetworkhashps": {(*float64)(nil)}, + "getnetworkinfo": {nil}, // TODO: document {(*btcjson.GetNetworkInfoResult)(nil)}, "getnodeaddresses": {(*[]btcjson.GetNodeAddressesResult)(nil)}, "getpeerinfo": {(*[]btcjson.GetPeerInfoResult)(nil)}, "getrawmempool": {(*[]string)(nil), (*btcjson.GetRawMempoolVerboseResult)(nil)},