From 5a491537ca915dd8e148ef7ec7f205dde8ceb741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Tue, 30 Nov 2021 10:16:40 +0100 Subject: [PATCH] tests: geth client wrapper (#774) --- server/config/config.go | 5 +++++ tests/e2e/integration_test.go | 27 ++++++++++++++++++++++++++- testutil/network/network.go | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index a064311e..5ec1b9d2 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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{ diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index ae5f3b6a..86979094 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -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" @@ -34,6 +37,8 @@ type IntegrationTestSuite struct { ctx context.Context cfg network.Config network *network.Network + + gethClient *gethclient.Client } func (s *IntegrationTestSuite) SetupSuite() { @@ -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() { @@ -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) diff --git a/testutil/network/network.go b/testutil/network/network.go index 62e205f7..8d7a9151 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -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()