Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ci

on: push

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: make build

- name: Test
run: make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@

# GoLand
.idea

tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

120 changes: 0 additions & 120 deletions Gopkg.lock

This file was deleted.

58 changes: 0 additions & 58 deletions Gopkg.toml

This file was deleted.

33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# supress output, run `make XXX V=` to be verbose
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
BUILD_PATH := $(dir $(MKFILE_PATH))
GOBIN ?= $(BUILD_PATH)tools/bin
ENV_PATH = PATH=$(GOBIN):$(PATH)

V := @

default: build

.PHONY: build
build:
$(V) go build ./...

.PHONY: test
test:
$(V)go test -mod=readonly -v ./...

.PHONY: vendor
vendor:
$(V)go mod tidy
$(V)go mod vendor

.PHONY: tools
tools:
@if [ ! -f $(GOBIN)/mockgen ]; then\
echo "Installing mockgen";\
GOBIN=$(GOBIN) go install github.com/golang/mock/mockgen;\
fi

.PHONY: generate
generate: tools
$(ENV_PATH) go generate ./...
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# scorum/scorum-go
[![Go Report Card](https://goreportcard.com/badge/github.com/scorum/scorum-go)](https://goreportcard.com/report/github.com/scorum/scorum-go)
[![GoDoc](https://godoc.org/github.com/scorum/scorum-go?status.svg)](https://godoc.org/github.com/scorum/scorum-go)
[![Build Status](https://travis-ci.org/scorum/scorum-go.svg?branch=master)](https://travis-ci.org/scorum/scorum-go)
[![Build Status](https://github.com/scorum/scorum-go/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/scorum/scorum-go/actions)

Golang RPC client library for [Scorum](https://scorumcoins.com). Both http and websocket transports are supported.
The websocket one allows to set callbacks.
Expand All @@ -15,14 +15,14 @@ import "github.com/scorum/scorum-go"
## Example
```go
import (
scorum "github.com/scorum/scorum-go"
"github.com/scorum/scorum-go/transport/http"
scorum "github.com/scorum/scorum-go"
"github.com/scorum/scorum-go/transport/http"
)

const testNet = "https://testnet.scorum.com"
const url = "https://testnet.scorum.work"

// create client
transport := http.NewTransport(testNet)
transport := http.NewTransport(url)
client := NewClient(transport)

// get last 100 transactions of the particular account
Expand Down
2 changes: 1 addition & 1 deletion apis/account_history/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

const nodeHTTPS = "https://testnet.scorum.com"
const nodeHTTPS = "https://testnet.scorum.work"

func TestGetAccountScrToScrTransfers(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
Expand Down
2 changes: 1 addition & 1 deletion apis/betting/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

const nodeHTTPS = "https://testnet.scorum.com"
const nodeHTTPS = "https://testnet.scorum.work"

func TestGetGameWinners(t *testing.T) {
t.Skip("need to start and finish game to get results")
Expand Down
2 changes: 1 addition & 1 deletion apis/blockchain_history/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

const nodeHTTPS = "https://testnet.scorum.com"
const nodeHTTPS = "https://testnet.scorum.work"

func TestGetBlockHeader(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
Expand Down
2 changes: 1 addition & 1 deletion apis/chain/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

const nodeHTTPS = "https://testnet.scorum.com"
const nodeHTTPS = "https://testnet.scorum.work"

func TestGetChainProperties(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
Expand Down
40 changes: 35 additions & 5 deletions apis/database/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package database

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/scorum/scorum-go/transport/http"
scorumhttp "github.com/scorum/scorum-go/transport/http"
"github.com/stretchr/testify/require"
)

const nodeHTTPS = "https://testnet.scorum.com"
const nodeHTTPS = "https://testnet.scorum.work"

func TestGetAccountsCount(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
transport := scorumhttp.NewTransport(nodeHTTPS)
api := NewAPI(transport)

count, err := api.GetAccountsCount(context.Background())
Expand All @@ -20,7 +22,7 @@ func TestGetAccountsCount(t *testing.T) {
}

func TestGetConfig(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
transport := scorumhttp.NewTransport(nodeHTTPS)
api := NewAPI(transport)

config, err := api.GetConfig(context.Background())
Expand All @@ -29,7 +31,7 @@ func TestGetConfig(t *testing.T) {
}

func TestLookupAccounts(t *testing.T) {
transport := http.NewTransport(nodeHTTPS)
transport := scorumhttp.NewTransport(nodeHTTPS)
api := NewAPI(transport)

t.Run("from beginning", func(t *testing.T) {
Expand Down Expand Up @@ -79,5 +81,33 @@ func TestLookupAccounts(t *testing.T) {
_, err := api.LookupAccounts(context.Background(), "", 2000)
require.Error(t, err)
})
}

func TestAPI_GetAccounts_ReturnNoError_When_ResponseIsNotJSONRPC(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
_, _ = writer.Write([]byte(`{"comment_count": "9,223,372,036,854,775,807"}`))
writer.WriteHeader(http.StatusOK)
}))

defer server.Close()

transport := scorumhttp.NewTransport(server.URL)
api := NewAPI(transport)
_, err := api.GetAccounts(context.Background(), "leo")
require.NoError(t, err)
}

func TestAPI_GetAccounts_ReturnError_When_CouldNotUnmarshallJSONRPCResult(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusOK)
_, _ = writer.Write([]byte(`{"id":0,"result":[{"comment_count": "9,223,372,036,854,775,807"}]}`))
}))

defer server.Close()

transport := scorumhttp.NewTransport(server.URL)
api := NewAPI(transport)
_, err := api.GetAccounts(context.Background(), "leo")

require.EqualError(t, err, "failed to unmarshal rpc result: [{\"comment_count\": \"9,223,372,036,854,775,807\"}]: json: cannot unmarshal string into Go struct field Account.comment_count of type int32")
}
Loading