mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
ethclient: add Version method to retrieve client version
This commit is contained in:
parent
7405dc5c4b
commit
406325a50c
2 changed files with 26 additions and 0 deletions
|
|
@ -77,6 +77,15 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) {
|
|||
return (*big.Int)(&result), err
|
||||
}
|
||||
|
||||
// Version retrieves the current client version.
|
||||
func (ec *Client) Version(ctx context.Context) (string, error) {
|
||||
var version string
|
||||
if err := ec.c.CallContext(ctx, &version, "web3_clientVersion"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
|
||||
// BlockByHash returns the given full block.
|
||||
//
|
||||
// Note that loading full blocks requires two requests. Use HeaderByHash
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -165,6 +168,9 @@ func TestEthClient(t *testing.T) {
|
|||
"ChainID": {
|
||||
func(t *testing.T) { testChainID(t, client) },
|
||||
},
|
||||
"Version": {
|
||||
func(t *testing.T) { testVersion(t, client) },
|
||||
},
|
||||
"GetBlock": {
|
||||
func(t *testing.T) { testGetBlock(t, client) },
|
||||
},
|
||||
|
|
@ -320,6 +326,17 @@ func testChainID(t *testing.T, client *rpc.Client) {
|
|||
}
|
||||
}
|
||||
|
||||
func testVersion(t *testing.T, client *rpc.Client) {
|
||||
ec := ethclient.NewClient(client)
|
||||
v, err := ec.Version(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if v != fmt.Sprintf("%s/%s-%s/%s", filepath.Base(os.Args[0]), runtime.GOOS, runtime.GOARCH, runtime.Version()) {
|
||||
t.Fatalf("Version returned wrong value: %s", v)
|
||||
}
|
||||
}
|
||||
|
||||
func testGetBlock(t *testing.T, client *rpc.Client) {
|
||||
ec := ethclient.NewClient(client)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue