mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-30 13:11:38 +00:00
rpc: allow using a custom http client in rpc client (#3779)
fixes #2010 * allow using a custom http client in rpc client * add tests and fix bug * fix confusion between remote and address * parse remote inside NewJSONRPCClientWithHTTPClient * cleanups * add warnings * add changelog entry * Update CHANGELOG_PENDING.md Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
@ -20,6 +20,7 @@ import (
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@ -41,6 +42,23 @@ func GetClients() []client.Client {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilCustomHTTPClient(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
client.NewHTTPWithClient("http://example.com", "/websocket", nil)
|
||||
})
|
||||
require.Panics(t, func() {
|
||||
rpcclient.NewJSONRPCClientWithHTTPClient("http://example.com", nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCustomHTTPClient(t *testing.T) {
|
||||
remote := rpctest.GetConfig().RPC.ListenAddress
|
||||
c := client.NewHTTPWithClient(remote, "/websocket", http.DefaultClient)
|
||||
status, err := c.Status()
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, status)
|
||||
}
|
||||
|
||||
func TestCorsEnabled(t *testing.T) {
|
||||
origin := rpctest.GetConfig().RPC.CORSAllowedOrigins[0]
|
||||
remote := strings.Replace(rpctest.GetConfig().RPC.ListenAddress, "tcp", "http", -1)
|
||||
|
Reference in New Issue
Block a user