tests: geth client wrapper (#774)

This commit is contained in:
Federico Kunze Küllmer 2021-11-30 10:16:40 +01:00 committed by GitHub
parent 5d2798aa7e
commit 5a491537ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -154,6 +154,11 @@ func GetDefaultAPINamespaces() []string {
return []string{"eth", "net", "web3"} 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 // DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
func DefaultJSONRPCConfig() *JSONRPCConfig { func DefaultJSONRPCConfig() *JSONRPCConfig {
return &JSONRPCConfig{ return &JSONRPCConfig{

View File

@ -11,8 +11,11 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "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/server/config"
"github.com/tharsis/ethermint/testutil/network" "github.com/tharsis/ethermint/testutil/network"
@ -34,6 +37,8 @@ type IntegrationTestSuite struct {
ctx context.Context ctx context.Context
cfg network.Config cfg network.Config
network *network.Network network *network.Network
gethClient *gethclient.Client
} }
func (s *IntegrationTestSuite) SetupSuite() { func (s *IntegrationTestSuite) SetupSuite() {
@ -53,11 +58,17 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = s.network.WaitForHeight(1) _, err = s.network.WaitForHeight(1)
s.Require().NoError(err) s.Require().NoError(err)
if s.network.Validators[0].JSONRPCClient == nil {
address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address) address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)
if s.network.Validators[0].JSONRPCClient == nil {
s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(address) s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(address)
s.Require().NoError(err) 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() { func (s *IntegrationTestSuite) TestChainID() {
@ -79,6 +90,20 @@ func (s *IntegrationTestSuite) TestChainID() {
s.Require().Equal(eip155ChainID, eip155ChainIDGen) 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() { func (s *IntegrationTestSuite) TestBlock() {
blockNum, err := s.network.Validators[0].JSONRPCClient.BlockNumber(s.ctx) blockNum, err := s.network.Validators[0].JSONRPCClient.BlockNumber(s.ctx)
s.Require().NoError(err) s.Require().NoError(err)

View File

@ -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.Address = fmt.Sprintf("0.0.0.0:%s", jsonRPCPort)
} }
appCfg.JSONRPC.Enable = true appCfg.JSONRPC.Enable = true
appCfg.JSONRPC.API = config.GetDefaultAPINamespaces() appCfg.JSONRPC.API = config.GetAPINamespaces()
} }
logger := log.NewNopLogger() logger := log.NewNopLogger()