tests: geth client wrapper (#774)
This commit is contained in:
parent
5d2798aa7e
commit
5a491537ca
@ -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{
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user