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

Commit 5a49153

Browse files
authored
tests: geth client wrapper (#774)
1 parent 5d2798a commit 5a49153

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

server/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ func GetDefaultAPINamespaces() []string {
154154
return []string{"eth", "net", "web3"}
155155
}
156156

157+
// GetAPINamespaces returns the all the available JSON-RPC API namespaces.
158+
func GetAPINamespaces() []string {
159+
return []string{"web3", "eth", "personal", "net", "txpool", "debug", "miner"}
160+
}
161+
157162
// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
158163
func DefaultJSONRPCConfig() *JSONRPCConfig {
159164
return &JSONRPCConfig{

tests/e2e/integration_test.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111

1212
"github.com/stretchr/testify/suite"
1313

14+
"github.com/ethereum/go-ethereum"
1415
"github.com/ethereum/go-ethereum/common"
1516
"github.com/ethereum/go-ethereum/ethclient"
17+
"github.com/ethereum/go-ethereum/ethclient/gethclient"
18+
"github.com/ethereum/go-ethereum/rpc"
1619

1720
"github.com/tharsis/ethermint/server/config"
1821
"github.com/tharsis/ethermint/testutil/network"
@@ -34,6 +37,8 @@ type IntegrationTestSuite struct {
3437
ctx context.Context
3538
cfg network.Config
3639
network *network.Network
40+
41+
gethClient *gethclient.Client
3742
}
3843

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

61+
address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)
62+
5663
if s.network.Validators[0].JSONRPCClient == nil {
57-
address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)
5864
s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(address)
5965
s.Require().NoError(err)
6066
}
67+
68+
rpcClient, err := rpc.DialContext(s.ctx, address)
69+
s.Require().NoError(err)
70+
s.gethClient = gethclient.New(rpcClient)
71+
s.Require().NotNil(s.gethClient)
6172
}
6273

6374
func (s *IntegrationTestSuite) TestChainID() {
@@ -79,6 +90,20 @@ func (s *IntegrationTestSuite) TestChainID() {
7990
s.Require().Equal(eip155ChainID, eip155ChainIDGen)
8091
}
8192

93+
func (s *IntegrationTestSuite) TestNodeInfo() {
94+
// Not implemented
95+
info, err := s.gethClient.GetNodeInfo(s.ctx)
96+
s.Require().Error(err)
97+
s.Require().Empty(info)
98+
}
99+
100+
func (s *IntegrationTestSuite) TestCreateAccessList() {
101+
// Not implemented
102+
accessList, _, _, err := s.gethClient.CreateAccessList(s.ctx, ethereum.CallMsg{})
103+
s.Require().Error(err)
104+
s.Require().Nil(accessList)
105+
}
106+
82107
func (s *IntegrationTestSuite) TestBlock() {
83108
blockNum, err := s.network.Validators[0].JSONRPCClient.BlockNumber(s.ctx)
84109
s.Require().NoError(err)

testutil/network/network.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
318318
appCfg.JSONRPC.Address = fmt.Sprintf("0.0.0.0:%s", jsonRPCPort)
319319
}
320320
appCfg.JSONRPC.Enable = true
321-
appCfg.JSONRPC.API = config.GetDefaultAPINamespaces()
321+
appCfg.JSONRPC.API = config.GetAPINamespaces()
322322
}
323323

324324
logger := log.NewNopLogger()

0 commit comments

Comments
 (0)