2017-10-11 14:20:51 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-01-02 09:10:19 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
|
|
|
"github.com/status-im/status-go/rpc"
|
2018-04-18 15:13:27 +00:00
|
|
|
"github.com/status-im/status-go/t/e2e"
|
2018-02-08 12:52:47 +00:00
|
|
|
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
2017-10-11 14:20:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RPCClientTestSuite struct {
|
2018-04-05 09:45:26 +00:00
|
|
|
e2e.StatusNodeTestSuite
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRPCClientTestSuite(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
e2e.Init()
|
2017-10-11 14:20:51 +00:00
|
|
|
suite.Run(t, new(RPCClientTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCClientTestSuite) SetupTest() {
|
2018-04-05 09:45:26 +00:00
|
|
|
s.StatusNode = node.New()
|
|
|
|
s.NotNil(s.StatusNode)
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RPCClientTestSuite) TestNewClient() {
|
2018-03-02 09:25:30 +00:00
|
|
|
config, err := 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)
|
|
|
|
}
|