Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

tests: geth client wrapper #774

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func GetDefaultAPINamespaces() []string {
return []string{"eth", "net", "web3"}
}

// GetAPINamespaces returns the all the available JSON-RPC API namespaces.
func GetAPINamespaces() []string {
return []string{"web3", "eth", "personal", "net", "txpool", "debug", "miner"}
}

// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
func DefaultJSONRPCConfig() *JSONRPCConfig {
return &JSONRPCConfig{
Expand Down
27 changes: 26 additions & 1 deletion tests/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (

"github.com/stretchr/testify/suite"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/ethereum/go-ethereum/rpc"

"github.com/tharsis/ethermint/server/config"
"github.com/tharsis/ethermint/testutil/network"
Expand All @@ -34,6 +37,8 @@ type IntegrationTestSuite struct {
ctx context.Context
cfg network.Config
network *network.Network

gethClient *gethclient.Client
}

func (s *IntegrationTestSuite) SetupSuite() {
Expand All @@ -53,11 +58,17 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)

address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)

if s.network.Validators[0].JSONRPCClient == nil {
address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)
s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(address)
s.Require().NoError(err)
}

rpcClient, err := rpc.DialContext(s.ctx, address)
s.Require().NoError(err)
s.gethClient = gethclient.New(rpcClient)
s.Require().NotNil(s.gethClient)
}

func (s *IntegrationTestSuite) TestChainID() {
Expand All @@ -79,6 +90,20 @@ func (s *IntegrationTestSuite) TestChainID() {
s.Require().Equal(eip155ChainID, eip155ChainIDGen)
}

func (s *IntegrationTestSuite) TestNodeInfo() {
// Not implemented
info, err := s.gethClient.GetNodeInfo(s.ctx)
s.Require().Error(err)
s.Require().Empty(info)
}

func (s *IntegrationTestSuite) TestCreateAccessList() {
// Not implemented
accessList, _, _, err := s.gethClient.CreateAccessList(s.ctx, ethereum.CallMsg{})
s.Require().Error(err)
s.Require().Nil(accessList)
}

func (s *IntegrationTestSuite) TestBlock() {
blockNum, err := s.network.Validators[0].JSONRPCClient.BlockNumber(s.ctx)
s.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
appCfg.JSONRPC.Address = fmt.Sprintf("0.0.0.0:%s", jsonRPCPort)
}
appCfg.JSONRPC.Enable = true
appCfg.JSONRPC.API = config.GetDefaultAPINamespaces()
appCfg.JSONRPC.API = config.GetAPINamespaces()
}

logger := log.NewNopLogger()
Expand Down