Browse Source

lite2: Default to http scheme in provider.New (#4649)

Closes: #4643
pull/4632/head
Alexander Bezobchuk 5 years ago
committed by GitHub
parent
commit
c11013f094
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions
  1. +8
    -2
      lite2/provider/http/http.go
  2. +16
    -0
      lite2/provider/http/http_test.go

+ 8
- 2
lite2/provider/http/http.go View File

@ -26,13 +26,19 @@ type http struct {
chainID string
}
// New creates a HTTP provider, which is using the rpchttp.HTTP
// client under the hood.
// New creates a HTTP provider, which is using the rpchttp.HTTP client under the
// hood. If no scheme is provided in the remote URL, http will be used by default.
func New(chainID, remote string) (provider.Provider, error) {
// ensure URL scheme is set (default HTTP) when not provided
if !strings.Contains(remote, "://") {
remote = "http://" + remote
}
httpClient, err := rpchttp.New(remote, "/websocket")
if err != nil {
return nil, err
}
return NewWithClient(chainID, httpClient), nil
}


+ 16
- 0
lite2/provider/http/http_test.go View File

@ -1,6 +1,7 @@
package http_test
import (
"fmt"
"os"
"testing"
@ -8,12 +9,27 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/lite2/provider/http"
litehttp "github.com/tendermint/tendermint/lite2/provider/http"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
)
func TestNewProvider(t *testing.T) {
c, err := http.New("chain-test", "192.168.0.1:26657")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://192.168.0.1:26657}")
c, err = http.New("chain-test", "http://153.200.0.1:26657")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1:26657}")
c, err = http.New("chain-test", "153.200.0.1")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1}")
}
func TestMain(m *testing.M) {
app := kvstore.NewApplication()
node := rpctest.StartTendermint(app)


Loading…
Cancel
Save