Eth API: make net_version return the chain ID.

This commit is contained in:
Raúl Kripalani 2023-03-11 23:26:26 +00:00
parent d7a2fdb5ba
commit 7ce92f1422
2 changed files with 17 additions and 7 deletions

View File

@ -2,9 +2,11 @@ package itests
import ( import (
"context" "context"
"strconv"
"testing" "testing"
"time" "time"
"github.com/filecoin-project/lotus/build"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/builtin"
@ -109,3 +111,16 @@ func TestEthGetGenesis(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, ethBlk.Hash, genesisHash) require.Equal(t, ethBlk.Hash, genesisHash)
} }
func TestNetVersion(t *testing.T) {
blockTime := 100 * time.Millisecond
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
ens.InterconnectAll().BeginMining(blockTime)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
version, err := client.NetVersion(ctx)
require.NoError(t, err)
require.Equal(t, strconv.Itoa(build.Eip155ChainId), version)
}

View File

@ -766,13 +766,8 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth
return ret, nil return ret, nil
} }
func (a *EthModule) NetVersion(ctx context.Context) (string, error) { func (a *EthModule) NetVersion(_ context.Context) (string, error) {
// Note that networkId is not encoded in hex return strconv.FormatInt(build.Eip155ChainId, 10), nil
nv, err := a.StateNetworkVersion(ctx, types.EmptyTSK)
if err != nil {
return "", err
}
return strconv.FormatUint(uint64(nv), 10), nil
} }
func (a *EthModule) NetListening(ctx context.Context) (bool, error) { func (a *EthModule) NetListening(ctx context.Context) (bool, error) {