Skip to content

Commit

Permalink
Add end-to-end to be run against Alexander testnet (#15)
Browse files Browse the repository at this point in the history
* Add end-to-end to be run against Alexander network

* Adjust nolint config

* Improve e2e tests to run inside a docker container

* Remove not needed dependencies

* Update client/client.go

Co-Authored-By: Vimukthi <[email protected]>
  • Loading branch information
2 people authored and pstehlik committed Sep 19, 2019
1 parent 4492d14 commit 9c9bcb4
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 28 deletions.
8 changes: 0 additions & 8 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,3 @@
[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"

[[constraint]]
name = "github.com/pierrec/xxHash"
version = "0.1.5"

[[constraint]]
branch = "development"
name = "github.com/ChainSafe/gossamer"
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,43 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

clean: ##clean vendor's folder. Should be run before a make install
clean: ##clean vendor folder. Should be run before a make install
@echo 'cleaning previous /vendor folder'
@rm -rf vendor/
@echo 'done cleaning'

install: ## Install Dependencies
install: ## installs dependencies
@command -v dep >/dev/null 2>&1 || go get -u github.com/golang/dep/...
@command -v golangci-lint >/dev/null 2>&1 || go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
@dep ensure

lint: ## runs linters on go code
lint: ## runs linters on go code
@golangci-lint run

lint-fix: ## runs linters on go code and automatically fixes issues
lint-fix: ## runs linters on go code and automatically fixes issues
@golangci-lint run --fix

test: ## runs all tests in project
@go test -v ./...
test: ## runs all tests in project against the RPC URL specified in the RPC_URL env variable or localhost
@go test -v -race ./...

test-cover: ## runs all tests in project and report coverage
test-cover: ## runs all tests in project against the RPC URL specified in the RPC_URL env variable
## or localhost and report coverage
@go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
@mv coverage.txt shared

test-dockerized: ## runs the tests in a docker container against the Substrate Default Docker image
test-dockerized: ## runs all tests in a docker container against the Substrate Default Docker image
@docker-compose build
@docker-compose up --abort-on-container-exit

run-substrate-docker: ## runs the Substrate Default Docker image
test-e2e-deployed: export RPC_URL?=wss://poc3-rpc.polkadot.io
test-e2e-deployed: ## runs only end-to-end (e2e) tests against a deployed testnet (defaults to Alexander (wss://poc3-rpc.polkadot.io) if RPC_URL is not set)
@docker build . -t gsrpc-test
@docker run --rm -e RPC_URL gsrpc-test go test -v github.com/centrifuge/go-substrate-rpc-client/teste2e

run-substrate-docker: ## runs the Substrate Default Docker image, this can be used to run the tests
docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 parity/substrate:latest-v1.0 --dev --rpc-external --ws-external

help: ## shows this help
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST)

.PHONY: clean install lint lint-fix test test-dockerized run-substrate-docker
8 changes: 7 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Client interface {
Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (
*rpc.ClientSubscription, error)

GetURL() string
//MetaData(cache bool) (*MetadataVersioned, error)
}

Expand All @@ -45,6 +46,11 @@ type client struct {
//metadataLock sync.RWMutex
}

// Returns the URL the client connects to
func (c client) URL() string {
return c.URL
}

// TODO move to State struct
//func (c *client) MetaData(cache bool) (m *MetadataVersioned, err error) {
// if cache && c.metadataVersioned != nil {
Expand All @@ -65,7 +71,7 @@ type client struct {
// return
//}

// Connect
// Connect connects to the provided url
func Connect(url string) (Client, error) {
log.Printf("Connecting to %v...", url)
c, err := rpc.Dial(url)
Expand Down
10 changes: 5 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Calling RPC methods
Simply instantiate the gsrpc with a URL of your choice, e. g.
api, err := gsrpc.NewSubstrateAPI("wss://substrate-rpc.parity.io/")
api, err := gsrpc.NewSubstrateAPI("wss://poc3-rpc.polkadot.io")
and run any of the provided RPC methods from the api:
Expand All @@ -34,15 +34,15 @@ Further examples can be found below.
Types
The package [types](http://localhost:6060/pkg/github.com/centrifuge/go-substrate-rpc-client/types/) exports a number
The package [types](https://godoc.org/github.com/centrifuge/go-substrate-rpc-client/types/) exports a number
of useful basic types including functions for encoding and decoding them.
To use your own custom types, you can simply create structs and arrays composing those basic types. Here are some
examples using composition of a mix of these basic and builtin Go types:
1. Vectors, lists, series, sets, arrays, slices: http://localhost:6060/pkg/github.com/centrifuge/go-substrate-rpc-client/types/#example_Vec_simple
1. Vectors, lists, series, sets, arrays, slices: https://godoc.org/github.com/centrifuge/go-substrate-rpc-client/types/#example_Vec_simple
2. Structs: http://localhost:6060/pkg/github.com/centrifuge/go-substrate-rpc-client/types/#example_Struct_simple
2. Structs: https://godoc.org/github.com/centrifuge/go-substrate-rpc-client/types/#example_Struct_simple
There are some caveats though that you should be aware of:
Expand All @@ -54,6 +54,6 @@ methods that implement the Encodeable/Decodeable interfaces. Examples for that a
types, you can find reference implementations of those here: types/enum_test.go , types/tuple_test.go and
types/vec_any_test.go
For more information about the types sub-package, see http://localhost:6060/pkg/github.com/centrifuge/go-substrate-rpc-client/types
For more information about the types sub-package, see https://godoc.org/github.com/centrifuge/go-substrate-rpc-client/types
*/
package gsrpc
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
gsrpc-network:
ipv4_address: 172.42.0.2
command: --dev --ws-external --rpc-external
rpc-client-tests:
gsrpc-test:
build: .
networks:
gsrpc-network:
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

type SubstrateAPI struct {
RPC *rpc.RPC
client *client.Client
Client *client.Client
}

func NewSubstrateAPI(url string) (*SubstrateAPI, error) {
Expand All @@ -38,6 +38,6 @@ func NewSubstrateAPI(url string) (*SubstrateAPI, error) {

return &SubstrateAPI{
RPC: rpc.NewRPC(clPtr),
client: clPtr,
Client: clPtr,
}, nil
}
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

gsrpc "github.com/centrifuge/go-substrate-rpc-client"
"github.com/centrifuge/go-substrate-rpc-client/config"
"github.com/centrifuge/go-substrate-rpc-client/types"
)

func Example_simpleConnect() {
Expand All @@ -37,7 +36,7 @@ func Example_simpleConnect() {
panic(err)
}

fmt.Println(types.Hex(hash))
fmt.Println(hash.Hex())
}

// TODO: add example for listening to new blocks
Expand Down
41 changes: 41 additions & 0 deletions teste2e/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
// Copyright (C) 2019 Centrifuge GmbH
//
// This file is part of Go Substrate RPC Client (GSRPC).
//
// GSRPC is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GSRPC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package teste2e

import (
"fmt"
"testing"

gsrpc "github.com/centrifuge/go-substrate-rpc-client"
"github.com/centrifuge/go-substrate-rpc-client/config"
"github.com/stretchr/testify/assert"
)

func TestGetBlockHashAndVersion(t *testing.T) {
api, err := gsrpc.NewSubstrateAPI(config.NewDefaultConfig().RPCURL)
assert.NoError(t, err)
hash, err := api.RPC.Chain.GetBlockHashLatest()
assert.NoError(t, err)
runtimeVersion, err := api.RPC.State.GetRuntimeVersionLatest()
assert.NoError(t, err)

fmt.Printf("Connected to node %v | latest block hash: %v | authoringVersion: %v | specVersion: %v | "+
"implVersion: %v\n", (*api.Client).GetURL(), hash.Hex(), runtimeVersion.AuthoringVersion,
runtimeVersion.SpecVersion, runtimeVersion.ImplVersion)
}

0 comments on commit 9c9bcb4

Please sign in to comment.