2017-10-11 14:20:51 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/node"
|
|
|
|
"github.com/status-im/status-go/geth/rpc"
|
2018-02-08 12:52:47 +00:00
|
|
|
e2e "github.com/status-im/status-go/t/e2e"
|
|
|
|
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
2017-10-11 14:20:51 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RPCClientTestSuite struct {
|
|
|
|
e2e.NodeManagerTestSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRPCClientTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(RPCClientTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCClientTestSuite) SetupTest() {
|
|
|
|
s.NodeManager = node.NewNodeManager()
|
|
|
|
s.NotNil(s.NodeManager)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCClientTestSuite) TestNewClient() {
|
2017-10-24 10:23:53 +00:00
|
|
|
config, err := e2e.MakeTestNodeConfig(GetNetworkID())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
2017-11-07 17:36:42 +00:00
|
|
|
// upstream disabled
|
2017-10-11 14:20:51 +00:00
|
|
|
s.False(config.UpstreamConfig.Enabled)
|
2017-11-07 17:36:42 +00:00
|
|
|
_, err = rpc.NewClient(nil, config.UpstreamConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
2017-11-07 17:36:42 +00:00
|
|
|
// upstream enabled with correct URL
|
2017-10-11 14:20:51 +00:00
|
|
|
upstreamGood := config.UpstreamConfig
|
|
|
|
upstreamGood.Enabled = true
|
|
|
|
upstreamGood.URL = "http://example.com/rpc"
|
2017-11-07 17:36:42 +00:00
|
|
|
_, err = rpc.NewClient(nil, upstreamGood)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
2017-11-07 17:36:42 +00:00
|
|
|
// upstream enabled with incorrect URL
|
|
|
|
upstreamBad := config.UpstreamConfig
|
|
|
|
upstreamBad.Enabled = true
|
|
|
|
upstreamBad.URL = "///__httphh://///incorrect_urlxxx"
|
|
|
|
_, err = rpc.NewClient(nil, upstreamBad)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.Error(err)
|
|
|
|
}
|